Jump to content
  • Advertisement

Archived

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

Santharn

how accessing data in other program parts/instances of classes?

This topic is 5793 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

Hi! I''ve written a class that creates an error log, that is able to open/close the error-file and one can add an message per "SetError"-method. class CErrorProtocol { public: CErrorProtocol( char* Filename ); ~CErrorProtocol (); void SetError( char *String ); private: char* m_strFilename; FILE* m_Protocol; }; The steering main-program creates an instance of this class dynamically. My problem is now, that all other instances of dynamically created classes (all other classes in my program) can''t add a message to the log, because they have no pointer/access to the errorlog-class (they don''t see it). What would the easiest/elegantest solution of this problem be? Would it be a solution to pass all instances of classes a pointer to the application, so it can relate to other program parts? How is the communication basically connected between class-instances (what is the matching feature/catch phrase in oop)? thanks for help!

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
can you think of a reason to not use a global variable? btw I didn''t say "recite" I said "think". Ok so maybe you have a reason. Does it outweigh the horribleness of making every single object in your game have an additional pointer for no reason whatsoever?

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
can you think of a reason to not use a global variable?

Don''t worry; he''ll feel better once you say "global singleton" because [mindless recital]once it''s a singleton, it''s no longer a variable[/mindless recital].

A global variable is a perfect solution to this. Just make sure only the main driver creates and destroys the object (that''s the facility a singleton provides).

Share this post


Link to post
Share on other sites
i have created the log now as a global variable.
But now i´m always getting an assertion error related to the delete-operator
i have absolutely no idea why this is happening

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!