我在 C++/CLI 中有以下接口:
public interface class ISharedPtrInterface
{
void PrintSharedPtr(std::shared_ptr<std::wstring> ptr);
};
其实现如下:
public ref class SharedPtrClass : public ISharedPtrInterface
{
public:
virtual void PrintSharedPtr(std::shared_ptr<std::wstring> ptr)
{
System::Console::WriteLine(gcnew System::String(ptr->c_str()));
};
};
在 Visual Studio 2010 中编译时,我收到以下警告:
1>TestSharedPtrInterface.cpp(8): warning C4679: 'ISharedPtrInterface::PrintSharedPtr' : could not import member
1> This diagnostic occurred while importing type 'ISharedPtrInterface ' from assembly 'AnotherCLRProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
如果我运行编译的方法,我会收到以下运行时错误:
Method 'PrintSharedPtr' in type 'SharedPtrClass' from assembly 'CLRProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
如果在接口/实现中使用直接的 std::wstring,则不会发生错误。谁能解释为什么?
非常感谢!