Jump to content
  • Advertisement

Archived

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

Erzengeldeslichtes

C++ Multiple friends, different access?

This topic is 5222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a manager class that has two functions that are needed by two seperate classes, but should not be visible to the other class. One is a destroy function, that adds an object to the list of objects to be deleted at the start of the next frame. I want the only object capable of doing that to be the object that is being added to the queue (I realize that friend''ing an object would allow all of those objects to delete each other, but since friends aren''t inheritted, I suppose it''s not that much of a problem). Another function is a method of getting a pointer to an object from a serial number that I want only accessible by a class specifically designed for it--one that gives access to the class members without access to the pointer itself (no calling delete! Use the Kill function, which is the one mentioned above). Now I suppose by simply locking out the source code to the base objects there''d be no problem, but... is there a way that I can make the pointer object not able to access the private function to delete the object, while providing access to the base object to delete itself but not able to access the pointer?

Share this post


Link to post
Share on other sites
Advertisement
Use interfaces to solve this problem.


class IDestroyer {
public:
virtual void destroy(void* ptr) = 0;
};

class IObjectHolder {
public:
virtual void* getObject(unsigned long serial_number) = 0;
};

class MyManager : public IDestroyer, IObjectHolder {
// implement the above two interfaces in here

};


Now the object that can delete things only gets a IDestroyer pointer, not a MyManager pointer. The class that needs the getObject() function only gets a IObjectHolder pointer, not a MyManager pointer.

Regards,
Jeff


[ CodeDread ]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!