我已經在C++/CLI如下界面: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'.
如果我運行編譯的方法,我得到以下運行時e RROR:
Method 'PrintSharedPtr' in type 'SharedPtrClass' from assembly 'CLRProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
如果在接口/實現使用直的std :: wstring的,不會發生錯誤。誰能解釋爲什麼?
非常感謝!
我不知道問題是什麼,但我知道你不需要的wstring中的unique_ptr – paulm
這僅僅是一個簡單的例子,重現我在一個更大的項目中遇到的錯誤。我知道在這種情況下我不需要shared_ptr,但我想了解警告。 – mickeyt