我有一個類,像這樣:問題,我用C++方法
class Qtree
{
public:
Qtree();
Qtree(BMP img, int d);
private:
class QtreeNode
{
public:
QtreeNode* nwChild; // pointer to northwest child
QtreeNode* neChild; // pointer to northeast child
QtreeNode* swChild; // pointer to southwest child
QtreeNode* seChild; // pointer to southeast child
RGBApixel element; // the pixel stored as this node's "data"
QtreeNode();
QuadtreeNode copy(QuadtreeNode & n);
};
所以問題是在複製方法。它製作給定節點的副本並將其返回。
QtreeNode Qtree::QtreeNode::copy(QtreeNode & n) {
QtreeNode *newNode;
//....
return newNode;
}
然後我打電話副本從我Qtree的拷貝構造函數:
root=QtreeNode::copy(*tree.root); //each tree has a root pointer
//have also tried many different things here, but dont really know what to put
我收到以下錯誤:
error: cannot call member function ‘Qtree::QtreeNode* Qtree::QtreeNode::copy(Qtree::QtreeNode&)’ without object
and
error: no matching function for call to ‘copy(Qtree::QtreeNode&)’
此外,我意識到我的複製方法返回一個指針,即使它不應該。這只是伴隨着我的整體困惑。我只是不知道如何工作.. – Snowman 2011-03-16 19:00:09
'副本()'沒有聲明爲靜態的。 – 2011-03-16 19:07:53
爲什麼不製作一個合適的拷貝構造函數而不是這個非規範的廢話? – 2011-03-16 19:08:37