Template function in eMbedded Visual C++ 4.0 for Windows CE
Does eMbedded Visual C++ 4.0 (SP4) support template functions? I get an error when I try to compile code that works fine in Visual C++ 6.0.
Here is my template function, which does compile:
template<class NodeType>
NodeType* MyFunction()
{
// ... do stuff
return new NodeType("foo"); // return a new class instance of type NodeType
}
Template Function Usage:
MyClass *myOjb = MyFunction<MyClass>(); // th开发者_开发百科is is causing an error
Compilation Errors:
error C2275: 'MyClass' : illegal use of this type as an expression
see declaration of 'MyClass'
error C2059: syntax error : ')'
Is there some compiler switch I need to change? How do I get this to compile?
Found the answer here.
"It works fine when the template function is not a class member. Oh well, I guess I'll have to leave it as a global function."
精彩评论