标签存档: VC++

VS2008:error C2259 cannot instantiate abstract class

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://connect.microsoft.com/VisualStudio/feedback/details/101072/error-c2259-cannot-instantiate-abstract-class#

Visual C++调试时查看数组内容

微软文档原文地址:

http://support.microsoft.com/?scid=kb%3Ben-us%3B198953&x=9&y=9

Starting with Visual C++ version 6.0, it is now possible to expand an array pointer to view all array elements in the Visual C++ Debugger Watch window. This feature is not documented.
从 Visual c + + 6.0 版开始,现在可以展开 Visual c + + 调试器监视窗口中查看所有数组元素的数组指针。 此功能未记录。

In the Watch window, type an expression that evaluates to a pointer followed by a comma and the number of elements in the array.
在监视窗口中键入一个表达式,该表达式计算为后跟一个逗号和数组中的元素数的指针。

  1. 作为控制台应用程序生成下面的代码的调试版本。
       // Filename main.cpp
       // No compile option needed
    
       #include <iostream.h>
    
       void main(void)
       {
         int * p;
         char* ptr = "Hello World";
         p = new int [10];
    
         for(int i=0; i<=9; i++){*(p+i) = i+1;}
         cout << i <<endl;
       }
  2. 使用调试器单步执行该代码,并在最后一行代码处停止。
  3. 在监视或 Quickwatch 窗口中添加变量 pptr。 您将看到变量旁边的 + 符号。
  4. 单击 + 符号以展开该变量。 您将看到它指向的数组中,只有第一个元素。
  5. 在监视窗口中现在,键入 p,10ptr,11
  6. 单击 + 符号以展开该变量。 现在,您看到它指向的数组的所有元素。

如果您要查看特定范围的元素,然后输入第一个元素来指定在上述步骤中所述跟格式说明符将起始索引的地址。 例如,(p+3),8 显示元素 p [3..10] 和 (ptr+3),10 显示元素 ptr [3..12]。 在监视窗口中的起始索引是 [0] 的不幸的是,这实际上对应于在此示例中的索引 3。 您必须记住偏移量 3 具有要添加到每个显示的索引,以获取数组元素的实际索引。

Canonical URL by SEO No Duplicate WordPress Plugin