C++ boost共享ptr接口/对象
假设我有一个API,它有两种方法可以相互结合使用:C++ boost共享ptr接口/对象,c++,boost,interface,shared-ptr,C++,Boost,Interface,Shared Ptr,假设我有一个API,它有两种方法可以相互结合使用: boost::shared_ptr<IAsset> getAsset( const std::string & id ); void update( const Asset & asset ); 我得到以下错误: \boost\include\boost/smart_ptr/shared_ptr.hpp(378): error C2440: '<function-style-cast>' :
boost::shared_ptr<IAsset> getAsset( const std::string & id );
void update( const Asset & 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
\boost\include\boost/smart\u ptr/shared\u ptr.hpp(378):错误C2440:'':无法从'boost::shared\u ptr'转换为'boost::shared\u ptr'
具有
[
T=iaset
]
和
[
T=资产
]
没有构造函数可以采用源类型,或者构造函数重载解析不明确
src\TestMethod.cpp(35):请参阅正在编译的函数模板实例化“boost::shared_ptr&boost::shared_ptr::operator=(boost::shared_ptr&&)”的参考
具有
[
T=资产
]
\boost\include\boost/smart\u ptr/shared\u ptr.hpp(378):错误C2228:“.swap”的左侧必须具有类/结构/联合
这里我应该注意到,Asset
的类定义扩展了iaset
,如class-Asset:virtualpublic-iaset{…}
由于我无法访问底层API,有人能告诉我正确的方法吗?我认为您对继承的使用是不正确的。如果
update
需要资产
,则需要向其发送资产
或其子类IAsset
是一个超类。我认为您对继承的使用是不正确的。如果update
需要资产
,则需要向其发送资产
或其子类IAsset
是一个超类。因为您将IAsset
转换为需要向下转换的资产。因为您将IAsset
转换为需要向下转换的资产。这是一种潜在的不安全转换,因此您必须使用
(请注意,您不能从虚拟基类使用静态\u cast
)这是一种潜在的不安全转换,因此您必须使用
(请注意,不能从虚拟基类使用静态\u cast
。)
\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