class - C++ Error: lvalue required as unary '&' operand -
i have created class named node. defined follows:
class node { private: int key; node * next; public: void setkey(int key); void setnext(node * next); int getkey(); node * getnext(); }; these functions basic getter , setter functions. now, if try this:
movenode(&(btail->getnext()),&start); it shows error :lvalue required unary '&' operand
now, if update class node , keep (node * next) public , access via this:
movenode(&(btail->next),&start); it shows no error.
please how can rid of error.
when return node* getnext(), create temporary variable of node* type, has no sense take address using &, temporary variable anyway destroyed soon.
when directly access next, refer long-living variable, , can take address.
you might want return reference node* getnext():
node*& getnext() {return next;}; so point same variable next , able take address.
Comments
Post a Comment