Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » prototype not found (MinGW doesnt understand defaults)
Re: prototype not found [message #51887 is a reply to message #51882] Tue, 11 June 2019 20:17 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
The code is supposed to look like below Rolling Eyes
#include <Core/Core.h>

using namespace Upp;

struct new_ {
	new_(int size=1, bool init=false)
	: size(size)
	, init(init)
	{}
	
	template <typename T>
	operator T() const { NEVER(); return T(); }
	
	template <typename T>
	operator T*() const {
		using T0 = typename std::remove_const<T>::type;
		if (size < 1) {return NULL;}
		T0 *p = NULL;
		p = new T0[size];
		if (!p) exit(-1);
		if (init) memset(p, 0, sizeof(T) * size);
		return p;
	}
	
private:
	const int size;
	const bool init;
};

CONSOLE_APP_MAIN
{
	const char* str1 = new_(12, true);
	std::string* pst = new_(12);
	delete [] pst;
	delete [] str1;
}


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: What is the difference between the memory management in C and C++?
Next Topic: Nested template question
Goto Forum:
  


Current Time: Fri Apr 26 20:27:51 CEST 2024

Total time taken to generate the page: 0.02542 seconds