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

Started by
3 comments, last by Captain P 14 years, 10 months ago
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]
Advertisement
Looks like you are calling Load with a NULL pointer.
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
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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. ;)
Create-ivity - a game development blog Mouseover for more information.

This topic is closed to new replies.

Advertisement