It is a compiler error or runtime error? The code below can be compiled!
class Base{
void g();
void h();
};
int main()
{
Base* p = new Base();
free(p);
return 0;
}
However it can't be compiled with a virtual function if I declare the class Base like this
class Base{
virtual void g();
void h();
};
The code below can be compiled all the time, no matter the function is virtual or not.
class Base{
void g();
void h();
};
int main()
{
Base* p = (Base*)malloc(sizeof(Base));
delete p;
return 0;
}