Jump to content
  • Advertisement
Sign in to follow this  
KiLLeR13iii

[Solved]Is there a way to use an object in a class?

This topic is 3332 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 don`t know if I put the right title to the thread. Anyway .. here is the problem. I have a two classes class model { ......... data types; methods; ......... } class obj { public: ........ model *m; obj() { m=new model(); //constructor } ........ void Load() { model->Load(); <------here it crashes when trying to call this method }; } The program crashes with an error like Unhandled exception at 0x004720c6 in PRG.exe: 0xC0000005: Access violation reading location 0x000000d4. Same thing happens when using model as static (model m;model.Load();) Any ideas why this happens and how to solve this? Ty in advance. [Edited by - KiLLeR13iii on June 6, 2009 4:43:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
NULL pointer ringed a bell. Stupid me forgot to create the object for the obj class(object =new obj(); in the main app). I`m programing for more than 12 hour now and i`m tired and just couldn`t figure it out. Thnx for the quick reply. If there wasn`t for u i would have go to sleep :P

Share this post


Link to post
Share on other sites
Quote:
Original post by KiLLeR13iii
I`m programing for more than 12 hour now and i`m tired and just couldn`t figure it out. Thnx for the quick reply. If there wasn`t for u i would have go to sleep :P
Go get that sleep - productivity drops way off when you stare at that screen for too long, and lack of sleep kills you even more.

Share this post


Link to post
Share on other sites
Do you really need to allocate obj's model dynamically? Why not just let obj contain a model instance directly? It's easy to introduce leaks or double deletions when you forget about your destructor or copy constructor/assignment operator.
class Obj
{
protected:
Model model;
};

Static refers to something else, bytheway. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!