Sign in to follow this  
KiLLeR13iii

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this