Advertisement

Simple (I hope) question about pointers

Started by July 22, 2001 08:23 AM
1 comment, last by Rottbott 23 years, 3 months ago
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
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
"The time has come", the Walrus said, "To speak of many things."
Advertisement
Excellent, thanks, I think I''ve got it working . Thanks again!


Rottbott

This topic is closed to new replies.

Advertisement