Jump to content

  • Log In with Google      Sign In   
  • Create Account

Simple (I hope) question about pointers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Rottbott   Members   -  Reputation: 145

Like
Likes
Like

Posted 22 July 2001 - 02:23 AM

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

Sponsor:

#2 sympathy   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 July 2001 - 02:42 AM

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

#3 Rottbott   Members   -  Reputation: 145

Like
Likes
Like

Posted 22 July 2001 - 03:41 AM

Excellent, thanks, I think I''ve got it working . Thanks again!


Rottbott




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS