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 PostI think you are getting confused. Think of the Nested class as a class of its own. The
only difference is its scope. You can only access it from the outer class. The nested
class has no association with the parent class, besides the scope resolution.What you are …
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.