How can a class's memory-allocated address be determined from within the contructor?

Posted by Jim Fell on Stack Overflow See other posts from Stack Overflow or by Jim Fell
Published on 2010-04-27T21:42:19Z Indexed on 2010/04/27 22:03 UTC
Read the original article Hit count: 203

Filed under:
|
|

Is it possible to get the memory-allocated address of a newly instantiated class from within that class's constructor during execution of said constructor? I am developing a linked list wherein multiple classes have multiple pointers to like classes. Each time a new class instantiates, it needs to check its parent's list to make sure it is included.

If I try to do something like this:

MyClass() // contructor
{
   extern MyClass * pParent;

   for ( int i = 0; i < max; i++ )
   {
      pParent->rels[i] == &MyClass; // error
   }
}

I get this error:

error C2275: 'namespace::MyClass' : illegal use of this type as an expression

Any thoughts or suggestions would be appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about class