J
james
Every class is better has own constructor and deconstructor itself, even if
compiler allow you do that. Class A func1 alway be called In your code. I
revised your code for you. every class will call func1 itself. then you
don't need to name"virturl" in class B.
class A
{
public:
virtual void Func1()
{
printf("this is class A");
};
void Func1Caller()
{
Func1();
}
~A()
{
Func1Caller();
}
};
class B : public A
{
public:
B();
~B();
void Func1(){ printf("this is class B\n");}
B::B() {}
B::~B(){ Func1Caller();}
};
int main()
{
B t;
return 0;
}
compiler allow you do that. Class A func1 alway be called In your code. I
revised your code for you. every class will call func1 itself. then you
don't need to name"virturl" in class B.
class A
{
public:
virtual void Func1()
{
printf("this is class A");
};
void Func1Caller()
{
Func1();
}
~A()
{
Func1Caller();
}
};
class B : public A
{
public:
B();
~B();
void Func1(){ printf("this is class B\n");}
B::B() {}
B::~B(){ Func1Caller();}
};
int main()
{
B t;
return 0;
}