eMbedded Visual C++ 4.0 (SP4) はテンプレート関数をサポートしていますか? Visual C++ 6.0 で正常に動作するコードをコンパイルしようとすると、エラーが発生します。
コンパイルするテンプレート関数は次のとおりです。
template<class NodeType>
NodeType* MyFunction()
{
// ... do stuff
return new NodeType("foo"); // return a new class instance of type NodeType
}
テンプレート機能の使用法:
MyClass *myOjb = MyFunction<MyClass>(); // this is causing an error
コンパイル エラー:
error C2275: 'MyClass' : illegal use of this type as an expression
see declaration of 'MyClass'
error C2059: syntax error : ')'
変更する必要があるコンパイラ スイッチはありますか? これをコンパイルするにはどうすればよいですか?