假设我有具有2个方法是在结合使用彼此的API:升压shared_ptr的接口/对象
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?