Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Simple (I hope) question about pointers

4: Adsense

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   

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

#2 sympathy   Members   

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   

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.