V
voidtwerp
The following code cant call derived::fn() , it is calling base::fn()
which is pure virtual.
(the same problem is ocurring if I do it outside of constructors also)
What am I doing wrong here?
class base
{
public:
virtual void fn(void)=0;
};
class derived
{
public:
void fn(void){};
};
class user
{
public:
user(){
derived d;
p=(base*)new derived();//What is wrong here?
if(p!=0)
p->fn();//exception because p->fn == 0
}
private:
base *p;
};
which is pure virtual.
(the same problem is ocurring if I do it outside of constructors also)
What am I doing wrong here?
class base
{
public:
virtual void fn(void)=0;
};
class derived
{
public:
void fn(void){};
};
class user
{
public:
user(){
derived d;
p=(base*)new derived();//What is wrong here?
if(p!=0)
p->fn();//exception because p->fn == 0
}
private:
base *p;
};