Hi all,
I'm gradually starting to make this transition from the world of C to C++, and now that I have a little progress, I have some things that are still a bit confusing to me. One of them is if I nest a class inside another class. If I'm inside the nested class, does "this" point to the nested class or the wrapper class? Likewise, what if I want to refer to one and the other separately. Can I get both this 's? If so, I suppose I could only do that from inside the nested class or else how would it know which instance of the nested class to get it from?...
Thanks,
Sean
smcguffee
0
Newbie Poster
Recommended Answers
Jump to PostIf you have composition, then the this refers to whichever "object" the current function is a member of.
class A { private: int somePrvInt; public: A() : somePrvInt(0) {} int getPrvInt() { return this->somePrvInt; // this refers to the current A object } }; class B { …
Jump to Post@Fbody: you covered two good cases, but none are about the OP's question.
If you have a nested class, then the this pointer, within a call to a member of the nested class, refers to an instance of the nested class (not its wrapper class). However, the nested class …
All 5 Replies
Fbody
682
Posting Maven
Featured Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
smcguffee
0
Newbie Poster
mrnutty
761
Senior Poster
smcguffee
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.