N
NewToCPP
I am trying to access a base class's virtual function from the drived
class function. It is complaining that the function is not static. Can
anyone tell me what is the problem in the below given program.
class Base
{
private:
unsigned short abc;
public:
Base ();
virtual ~Base ();
virtual int myVirt (char *, const EnumMode);
};
int Base::myVirt (char *buffer, const EnumMode mode)
{
int offset = 0;
Base* pFrame = (Base *)(void *)(buffer + offset);
return offset + 2;
}
class Derived
{
private:
unsigned long dAbc;
public:
Derived ();
virtual ~Derived ();
virtual int myVirt (char *, const EnumMode);
};
int Derived::myVirt (char *buffer, const EnumMode mode)
{
int offset = 0;
offset = Base::myVirt (buffer, mode);
return offset + 4;
}
c:\testFile.h(64) : error C2352: 'Base::myVirt' : illegal call of
non-static member function
c:\testFile.h(31) : see declaration of 'myVirt'
class function. It is complaining that the function is not static. Can
anyone tell me what is the problem in the below given program.
class Base
{
private:
unsigned short abc;
public:
Base ();
virtual ~Base ();
virtual int myVirt (char *, const EnumMode);
};
int Base::myVirt (char *buffer, const EnumMode mode)
{
int offset = 0;
Base* pFrame = (Base *)(void *)(buffer + offset);
return offset + 2;
}
class Derived
{
private:
unsigned long dAbc;
public:
Derived ();
virtual ~Derived ();
virtual int myVirt (char *, const EnumMode);
};
int Derived::myVirt (char *buffer, const EnumMode mode)
{
int offset = 0;
offset = Base::myVirt (buffer, mode);
return offset + 4;
}
c:\testFile.h(64) : error C2352: 'Base::myVirt' : illegal call of
non-static member function
c:\testFile.h(31) : see declaration of 'myVirt'