[Solved]Is there a way to use an object in a class?
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]
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 KiLLeR13iiiGo get that sleep - productivity drops way off when you stare at that screen for too long, and lack of sleep kills you even more.
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
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.
Static refers to something else, bytheway. ;)
class Obj{protected: Model model;};
Static refers to something else, bytheway. ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement