[class.mfct.non-static] (original) (raw)
:
struct tnode { char tword[20]; int count; tnode* left; tnode* right; void set(const char*, tnode* l, tnode* r); };
void tnode::set(const char* w, tnode* l, tnode* r) { count = strlen(w)+1; if (sizeof(tword)<=count) perror("tnode string too long"); strcpy(tword,w); left = l; right = r; }
void f(tnode n1, tnode n2) { n1.set("abc",&n2,0); n2.set("def",0,0); }
In the body of the member function tnode::set, the member namestword, count, left, and right refer to members of the object for which the function is called.
Thus, in the call n1.set("abc",&n2,0), tword refers ton1.tword, and in the call n2.set("def",0,0), it refers to n2.tword.
The functions strlen, perror, andstrcpy are not members of the class tnode and should be declared elsewhere.102
— end example