繁体   English   中英

嵌入式 Visual C++ 4.0 中的模板 function 用于 Windows CE

[英]Template function in eMbedded Visual C++ 4.0 for Windows CE

eMbedded Visual C++ 4.0 (SP4) 是否支持模板功能? 当我尝试编译在 Visual C++ 6.0 中运行良好的代码时出现错误。

这是我的模板 function,它可以编译:

template<class NodeType>
NodeType* MyFunction()
{
    // ... do stuff
    return new NodeType("foo"); // return a new class instance of type NodeType
}

模板 Function 用法:

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 : ')'

我需要更改一些编译器开关吗? 我如何让它编译?

这里找到了答案。

“当模板 function 不是 class 成员时,它可以正常工作。哦,好吧,我想我必须将其保留为全局 function。”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM