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)
prototype not found [message #51851] Sun, 09 June 2019 18:59 Go to previous message
Leander is currently offline  Leander
Messages: 9
Registered: January 2019
Promising Member
Hi together.

Have got this code here:
#include <string>
#include <stdlib.h>	
using namespace std;

template <typename T>
T* new_(int size=1, bool init=false);

template <typename T>
T* new_(int size, bool init)
{
	if (size < 1) {return NULL;}
	T *p = NULL;
	if (size==1) {p = new T;}
	else {p = new T[size];}
	if (!p) exit(-1);
	if (init) memset(p, 0, sizeof(T) * size);
	return p;
}

int main()
{
	std::string *pst;
	pst = (string*)new_();
	return 0;
}


The return "pst" should be enough to know what is a T.
But even the cast doesnt help (couldn't deduce...), see below.
Now I can call it with args or without and the MinGW will rant it (return.txt):

main.cpp: In function 'int main()':
main.cpp:28:22: error: no matching function for call to 'new_()'
main.cpp:28:22: note: candidate is:
main.cpp:14:4: note: template<class T> T* new_(int, bool)
main.cpp:14:4: note:   template argument deduction/substitution failed:
main.cpp:28:22: note:   couldn't deduce template parameter 'T'


And it suggests the only existing always, the upper prototype,
but doesnt accept it.
Someone has got a tip?

Martin
 
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: Thu Apr 25 21:02:45 CEST 2024

Total time taken to generate the page: 0.03713 seconds