0

我在 DLL 中创建了一个类(它使用 /clr 运行时,ManagedC++),并在该类中定义了一个构造函数。代码如下:

//Following is defined in something.h//

namespace ABC
{
public ref Class XYZ
{
public: int a;
public: XYZ();
};

//In something.cpp, I've the below code to define the constructor of the class created//

#include something.h

namespace ABC
{
 XYZ::XYZ()
  {
     a = 100;
  }
}

上面的项目内置在一个 DLL 中

在另一个项目中,我尝试使用 XYZ 类,如下所示:

#include something.h
using namespace ABC;

//inside main, I've following code

{
ABC::XYZ^ prq = gcnew ABC:XYZ();
prq->a=200;

......
...
}

在这,我得到一个错误说 -

unresolved token (06000001) ABC.XYZ::.ctor

你能帮忙看看这里有什么问题吗?

4

1 回答 1

1

问题是链接器找不到构造函数的定义。它位于另一个 DLL 中。在托管项目中,您可以通过添加对程序集的引用来解决这个问题。右键单击您的项目、属性、通用属性、框架和引用。单击添加新引用按钮。如果项目位于同一解决方案中,请使用“项目”选项卡。浏览选项卡,否则。

Also note that you now no longer need the .h file anymore. Declarations are imported from the metadata in the assembly.

于 2012-10-08T12:21:36.127 回答