我有休耕類:添加構件的boost :: ptr_vector <>
class CpuUsage {
public:
CpuUsage();
virtual ~CpuUsage();
void SetCpuTotalTime(CpuCore _newVal);
CpuCore GetCpuTotalTimes();
void AddSingleCoreTime(CpuCore& newval);
private:
CpuCore total;
boost::ptr_vector<CpuCore> cpuCores;
};
和
class CpuCore {
public:
CpuCore();
CpuCore(int _coreId, long _user, long _nice, long _sysmode,
long _idle, long _iowait, long _irq, long _softirq, long _steal,
long _guest);
//all variable declarations...
}
對於添加CpuCore對象到cpuCores矢量,我要補充的指針?或者,我可以複製的價值,normaly,如:
void CpuUsage::AddSingleCoreTime(CpuCore _newVal) {
cpuCores.push_back(_newVal);
}
隨着CpuCore * _newVal參數,我有以下錯誤:
../src/usage/CpuUsage.h:42:錯誤:「升壓:: ptr_vector> CpuUsage :: cpuCores'是私人的 ../src/NodeInfoGather.cpp:73:錯誤:在這種情況下
什麼問題的矢量是私人在這裏?
感謝,
您應該添加一個指針,'boost :: ptr_vector <>'擁有指針及其指向的內容。爲什麼不使用'std :: vector <>'? –
我在這篇文章中使用了boost ptr向量:http://stackoverflow.com/questions/2693651/c-vector-of-objects-vs-vector-of-pointers-to-new-objects –
你不似乎在給定的代碼上具有多於'CpuCore'的多態性。然而,發佈的代碼並不真實,「AddSingleCoreTime」的聲明和定義不同。 –