I have a class like so:
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);
};
And so the question is on the copy method. It makes a copy of a given node and returns it.
QtreeNode Qtree::QtreeNode::copy(QtreeNode & n) {
QtreeNode *newNode;
//....
return newNode;
}
And then I call copy from my Qtree copy constructor:
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
I get the following errors:
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&)’
try:
or better create copy constructor.
copyis instance method, it means that it can be run only with object provided. It’s internal signature as a function is:So you have to pass to parameters. Notation
obj->copy(..)is used, but it is actually passingobjas first parameter.