Archived

This topic is now archived and is closed to further replies.

Rottbott

Simple (I hope) question about pointers

Recommended Posts

Hi, Can someone tell me how I can find out the pointer to an object from within that object''s constructor? So...: // Constructor for ''Object'' class Object::Object(void) { Object * PointerToMe = ???; } Thanks! Rottbott

Share this post


Link to post
Share on other sites
class Object
{
private:
Object *oInstance;
public:
Object(void);
};

Object::Object(void)
{
Object *oInstance = this;
}

A class definition has one set of methods used for all instances of that class. So in order to differentiate between instances an invisible pointer known as this stores the invoking object. So pretend I do this:

int main(void)
{
Object oMain;
return 0;
}

oMain is invoking the constructor, so it's constructor will take this (referring to oMain), and assign it to oInstance pointer. Hope this helped. Good luck.

Edited by - sympathy on July 22, 2001 9:43:34 AM

Share this post


Link to post
Share on other sites