V
V Patel
I am trying to understand the behaviour for the following two cases:
class A {
virtual funcA() {i++;}; // case 1
funct A() {i++;}; // case 2
private:
int i;
};
main ()
{
A *a = new A();
A *b = a;
delete a;
b->functA()
}
case 1 fails (is this because it has to go thru vptr table and the object is
gone)
case 2 ok. (is this because its static binding. Though no object. Isn't this
unsafe?)
Also, are default constructor, copy constructor etc required from mere
presence
of any virtual function (non-trivial case) in a class?
thanks
class A {
virtual funcA() {i++;}; // case 1
funct A() {i++;}; // case 2
private:
int i;
};
main ()
{
A *a = new A();
A *b = a;
delete a;
b->functA()
}
case 1 fails (is this because it has to go thru vptr table and the object is
gone)
case 2 ok. (is this because its static binding. Though no object. Isn't this
unsafe?)
Also, are default constructor, copy constructor etc required from mere
presence
of any virtual function (non-trivial case) in a class?
thanks