Visual Studio2008编译错误error C2259 cannot instantiate abstract
class
经过检查,发现源代码中确实已经派生了虚函数,派生的虚函数源文件也正常编译。
最后在微软的官方网站上找到了答案(可能只是error C2259其中一种可能的原因,供参考):
This behavior is by design with VS 2005. The root cause is
because wchar_t is a different type than unsigned short though in
prior versions of Visual C++, the compiler considered them to be
the same type. In this sample code, the type library uses unsigned
short but the C++ source files use wchar_t. So the types don’t
match therefore the functions that contain these types in their
signatures don’t override the interface.
在VS 2005/VS2008中,wchar_t和unsigned short是不同的类型,尽管在之前的Visual
C++版本中编译器将两者视为了相同的类型。由于参数类型的不匹配导致编译器无法正确地识别或编译重载的接口。
To continue working with this sample, either correct the type
mismatch or use the /Zc:wchar_t- compiler switch to force the
compiler to consider wchar_t the same type as unsigned short.
In the VS 2005 project property properties, under the C/C++ node,
select Language. Then change “Treat wchar_t as Built-In Type” from
“Yes” to “No”.
解决办法:使用/Zc:wchar_t-编译选项强制让编译器将wchar_t 和 unsigned short视为相同类型。或者在VS
2005/VS2008中,将项目属性中将”Treat wchar_t as Built-In Type”一项设置为”No”.
微软相关链接地址:
博客来源:http://nariver.com/archives/486