假设我有一个 API,它有 2 个方法可以相互结合使用:
boost::shared_ptr<IAsset> getAsset( const std::string & id );
void update( const Asset & asset );
boost::shared_ptr<Asset> asset
我在另一个类中有一个成员变量。如果我做:
asset = otherObject->getAsset("first_asset");
// do some stuff
otherObject->update( *asset );
我收到以下错误:
\boost\include\boost/smart_ptr/shared_ptr.hpp(378): error C2440: '<function-style-cast>' : cannot convert from 'boost::shared_ptr<T>' to 'boost::shared_ptr<T>'
with
[
T=IAsset
]
and
[
T=Asset
]
No constructor could take the source type, or constructor overload resolution was ambiguous
src\TestMethod.cpp(35) : see reference to function template instantiation 'boost::shared_ptr<T> &boost::shared_ptr<T>::operator =<IAsset>(boost::shared_ptr<IAsset> &&)' being compiled
with
[
T=Asset
]
\boost\include\boost/smart_ptr/shared_ptr.hpp(378): error C2228: left of '.swap' must have class/struct/union
我应该在这里注意到,类定义Asset
确实扩展IAsset
为class Asset : virtual public IAsset {...}
有人可以告诉我正确的方法吗,因为我无法访问底层 API?