标签存档: Visual studio

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 Studio LNK2005 error

环境:  Visual Studio 2008 C++

编译错误: error LNK2005: _DllMain@12 already defined …

The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked.

微软的支持文档指出,MFC库的链接必须在CRT库之前,而解决方法有2种:

1. 强制连接器以正确的顺序链接,具体方法见下面的微软链接。

2. 在Linker标签页中,找到Command Line属性,并添加附加选项: /verbose:lib,重新编译工程,工程会列出详细的库清单,根据输出的内容来修正有问题的组件。

其中如果使用的是MFC库,确保每一个工程文件都包含头文件 #include <Stdafx.h>。

http://support.microsoft.com/kb/148652

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