问题是我为什么会收到以下错误以及如何修复错误:
error C2664: 'work<T>::setPrev' : cannot convert parameter 1 from 'boost::shared_ptr<T>' to 'boost::shared_ptr<T>'
cCapital类中对函数setPrev的调用给出了错误。
template <class T> class work
{
public:
work(const T & value):m_prev(), m_data(value) {}
~work(){}
boost::shared_ptr<work> getPrev() const {return m_prev;}
const T & value() const {return data;}
void setPrev(boost::shared_ptr<work> elem) {m_prev = elem;}
void setValue(const T & value) {data = value;}
private:
boost::shared_ptr<work> m_prev;
T m_data;
};
class cAssetBase
{
public:
cAssetBase(const std::string & desc):m_desc(desc){}
~cAssetBase(){}
const std::string & getDesc() const
{
return m_desc;
}
private:
std::string m_desc;
};
class cAsset: public work<cAssetBase>
{
public:
cAsset(const int & id, const std::string & symbol):m_id(id),work(cAssetBase(symbol)){}
~cAsset(){}
protected:
int m_id;
};
class cCapitalBase
{
public:
cCapitalBase(const std::string & desc):m_desc(desc){}
~cCapitalBase(){}
const std::string & getDesc() const
{
return m_desc;
}
private:
std::string m_desc;
};
class cCapital: public work<cCapitalBase>
{
public:
cCapital(const int & id, const std::string & symbol, boost::shared_ptr<cAsset> & asset):m_id(id),work(cCapitalBase(symbol)),m_asset(asset)
{
setPrev(m_asset);
}
~cCapital(){}
protected:
int m_id;
boost::shared_ptr<cAsset> m_asset;
};