visual studio 2010 - C++/CLI "could not import member" warning when using shared_ptr as argument -
i have following interface in c++/cli:
public interface class isharedptrinterface { void printsharedptr(std::shared_ptr<std::wstring> ptr); };
which implemented follows:
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())); }; };
compiling in visual studio 2010, following warning:
1>testsharedptrinterface.cpp(8): warning c4679: 'isharedptrinterface::printsharedptr' : not import member 1> diagnostic occurred while importing type 'isharedptrinterface ' assembly 'anotherclrproject, version=0.0.0.0, culture=neutral, publickeytoken=null'.
if run compiled method, following runtime error:
method 'printsharedptr' in type 'sharedptrclass' assembly 'clrproject, version=0.0.0.0, culture=neutral, publickeytoken=null' not have implementation.
the error not occur if using straight std::wstring in interface/implementation. can explain why?
many thanks!
you mixing native , managed types @ public interface level. is, in case have public managed interface method takes native types parameter. in general, isn't great idea, since can't use these methods managed language c# since can't supply native type.
the problem here has visibility of native types: default native types private. when tries import isharedptrinterface::printsharedptr
needs have have access interface (which since public) , access parameter types.
you can mark native types public using make_public
or directly marking them public (when compiling /clr).
the problem there no way make templated types public (make_public not work on them).
see:
Comments
Post a Comment