c++ - Recursive pointer function -
i struggling implement method called find_set within class blob. recursive function returns pointer blob object. blob class linked list , function supposed passed blob , recursively traverse blob's parents until arriving @ head of blob list. @ work having recreate components. not copy , pasted version of code, want know how time home.
class blob{ public: int size; int index[2]; char value; blob *parent; blob *find_set(blob* &in_question); };
the necessary elements of blob class understand conundrum.
blob* blob::find_set(blob* &in_question){ if(in_question!=nullptr) in_question.parent= find_set(&in_question.parent); return in_question; }
i hope have been explicit enough.
so, i'm guessing problem here:
blob* blob::find_set(blob* &in_question){ if(in_question!=nullptr) in_question.parent= find_set(&in_question.parent); return in_question; }
i'm not quite sure why you're taking reference pointer, here's working version of code:
blob* blob::find_set(blob* in_question){ if(in_question != nullptr) in_question->parent = find_set(in_question->parent); return in_question; }
- accessing members of pointer requires using
->
instead of.
- taking address of
in_question->parent
yields object of typeblob**
, not want
Comments
Post a Comment