Question

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>(); // this 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?

Was it helpful?

Solution

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."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top