I've got the following (truncated) class declaration:
template <typename T>
class btree
{
public:
btree(const btree<T>& original); //This is btree's copy constructor
private:
struct btree_node
{
btree_node(const btree_node &other)
{
//This is node's copy constructor
}
}
btree_node* headNode;
}
And btree's copy constructor is implemented this way:
template <typename T>
btree<T>::btree(const btree<T>& original)
{
headNode = new btree_node(original.*headNode);
}
original.*headNode is supposed to return btree_node that original.headNode is pointing to, thus matching btree_node's copy constructor arguments.
However I get the following error:
error: '((btree*)this)->btree::headNode' cannot be used as a member pointer, since it is of type 'btree::btree_node*'
What am I doing wrong?
If you look at the precedence table you will see that first the . operator is evaluated and then the * (dereference) operator is evaluated.
* takes a pointer as argument. If you write original.*headNode, it's meaningless. Somehow you are telling it to get the member *headNode of original, but *headNode is not a member of original. You are also telling it to evaluate *headNode which is actually *this->headNode (note that -> is evaluated first).
What you want is to first get the pointer by writing original.headNode, then dereference it by using *. Therefore
*original.headNode
Try this:
headNode = new btree_node(*(original.headNode))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With