Add Announcement Here

Using this pointer in the initialiser list

Using this pointer in the initialiser list

You know, it's fun like the constructor/destructor that makes me get out of bed to code c++. There is all sorts of fun stuff that can happen, for instance if you use a virtual function during destruct/construct it may be possible for the parent to call the child's function, and because the child has already been destroyed, you're fucked.

Now the prompt for this post came when making nested classes have access to their containing class:

Code:


class topNest{
protected:
   void callback(); // innerNest can use.

   class innerNest{
      public:
         innerNest(topNest &parent);

      private:
         topNest &mParent;
   };
   friend class innerNest;
};

continued...

Edited By: stu
Thu-10-12 07:52:51

stu
useravatar
Offline
680 Posts
User info in posts
Administrator has disabled public posting

Re: Using this pointer in the initialiser list

As we know, using the 'this' pointer is dangerous during construct/destruct, but c++ lets you ride the tiger if you choose.

http://stackoverflow.com/questions/5058 … ation-list

stu
useravatar
Offline
680 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
246
Total Polls:
0
Total Posts:
475
Dormant:
User Info:
 
Total Users:
7
Newest User:
ian96
Members Online:
0
Guests Online:
49

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked
gamestool, Powered by Joomla! and designed by SiteGround Joomla Templates