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 #51930 is a reply to message #51851] |
Fri, 21 June 2019 17:59 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Leander wrote on Sun, 09 June 2019 18:59Hi 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.
No, it is not. Types only can get resolved as parameters. But, good news, you can specify it directly:
pst = new_<string>();
[Updated on: Fri, 21 June 2019 17:59] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Apr 25 09:14:41 CEST 2024
Total time taken to generate the page: 0.02824 seconds
|