我正在尝试实现接口类的类实例。使用项目浏览器探索界面(.NET DLL),它说:
bool CreateInstance(SharedLibrary::MemoryArbiter^ pntMemory,
SharedLibrary::clsMessageQueue^ pntMessageQueue,
SharedLibrary::clsGPIO^ pntGPIO,
SharedLibrary::Types^ pntProgramSettings,
SharedLibrary::DisplayDriver^ pntDisplayDriver)
Member from Plugin_Interface::IPlugin
但如果我在MyClass.h中写道:
using namespace System;
using namespace System::ComponentModel;
using namespace SharedLibrary;
namespace MyCppPlugin {
[AttributeUsageAttribute(AttributeTargets::Class | AttributeTargets::Method |
AttributeTargets::Property | AttributeTargets::Field,
AllowMultiple = true, Inherited = false)]
ref class MyPlugin abstract : public Plugin_Interface::IPlugin
{
bool CreateInstance(SharedLibrary::MemoryArbiter^ pntMemory,
SharedLibrary::clsMessageQueue^ pntMessageQueue,
SharedLibrary::clsGPIO^ pntGPIO, SharedLibrary::Types^
pntProgramSettings, SharedLibrary::DisplayDriver^ pntDisplayDriver);
};
};
它说:“错误C3766:缺少Plugin_Interface :: IPlugin :: CreateInstace(...)的实现
我做错了什么?
修改
忘记抽象陈述。
并且:为什么说“IntelliSense:Class无法实现接口成员函数”Plugin_Interface :: IPlugin :: CreateInstance“(在”Plugin_Interface.dll“中声明)”
???
答案 0 :(得分:1)
您从此代码段获得了更多诊断消息,您犯了几个错误:
第三个和第四个项目符号是“必须提供接口方法的实现”编译错误的主要原因。所以正确的代码应该类似于这样的东西:
[NoIdeaWhatAttribute]
public ref class MyPlugin : public Plugin_Interface::IPlugin {
public:
virtual bool CreateInstance(SharedLibrary::MemoryArbiter^% pntMemory,
SharedLibrary::clsMessageQueue^% pntMessageQueue,
SharedLibrary::clsGPIO^% pntGPIO,
SharedLibrary::Types^% pntProgramSettings,
SharedLibrary::DisplayDriver^% pntDisplayDriver)
{
// Todo...
return false;
}
};
答案 1 :(得分:0)
我明白了。感谢Hans Passant给了我很多提示:)
要导出它必须实现接口1:1的功能。必须在类标题上添加export语句:
[Export(IPlugin::typeid)]
public ref class MyPlugin : public Plugin_Interface::IPlugin
并且:虽然VB.NET将编译为“任何CPU”,而C ++ / CLI将编译为Win64 / Win32,但它将缺失。两个项目必须具有相同的目标 - 64位或32位。
现在可行。