The first template seems to work just fine.
The second one gives me this error no matter how I try to modify the syntax.
"|19|error: template-id 'CreateUnit<char*>' for 'char* CreateUnit(int)' does not match any template declaration|"
Removing the argument does nothing, changing the "<char*>" to "<char>" does nothing.
Googling has not helped. Infact, most seem to propose the same thing I have here, but it won't compile.
I simply want the specialization to create a newly allocated NBTS style string.
1 2
char* temp = newchar[length];
return temp;
A simple string generator that is to be passed to a resource manager.
How on earth would I specialize this?
1 2
template <>
char* CreateUnit <char*>(int length);
It needs to take an int for the length, so I'm not sure how to approach this as a specialization.
And please don't insist I just don't use specialization, I'd really like to know how to do it.
I would like to be able to explicitly instantiate them like I can the generic template, ex
I don't think it's clear what you are trying to do. Are you trying to make a function that creates some number of units?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
template<typename T>
T *CreateUnits(int num)
{
returnnew T[num];
}
//Which you could specialize:
template<>
char *CreateUnits<char *>(int num)
{
// This isn't really a specialization - perhaps you have some special code to go here.
returnnewchar[num];
}