Hi to everyone
I'm writing this post because I have some problems accessing a function of a class through a pointer.
This is the situation:
I have a pointer to a class. The class inherits two virtual functions from an abstract base class.
The problem is the following:
When I try to call the function from the pointer I receive the following error at run-time: "Unhandled exception at 0x004251d8 in MyApplication.exe: 0xC0000005: Access violation reading location 0x00000000."
Can somebody help me, please?
here the declaration of the pointer and the functions:
Code:
//baseclass.h
class MyBaseClass
{
public:
virtual void Start() = 0;
virtual void Stop() = 0;
};
//class.h
class MyClass : public MyBaseClass
{
public:
MyClass();
void Stop();
};
//pointer
static MyClass *MyClassptr;
//myclass.cpp
MyClass::MyClass()
{
MyClassptr=this;
}
//main.cpp
int main()
{
MyClass MyNewClass;
MyClassptr->Start();
return 0;
}