调用dll管理的C++;

调用dll管理的C++;,dll,managed-c++,Dll,Managed C++,我在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

我在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;
  }
}
#include something.h
using namespace ABC;

//inside main, I've following code

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

......
...
}
上面的项目被构建到一个DLL中

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

//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;
  }
}
#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

你能帮个忙吗?

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


还要注意的是,您现在不再需要.h文件了。声明是从程序集中的元数据导入的。

没错!正如你提到的,我在包含headerfile时遇到了错误。我已经包含了名称空间。试图重新定义错误XYZ()。但我不明白,包含一个headerfile是如何让它被重新定义的?