R
Rahul
Hi Everyone,
I was trying to implement a final class and i start having the
destructor of the final class as private,
class A
{
~A()
{
printf("destructor invoked\n");
}
};
class B : public A
{
public : ~B()
{
}
};
int main()
{
return 0;
}
And as expected i get a compilation error, saying "cannot access
private member A::~A declared in A"
But when i change the derived class like the following,
class B : public A
{
}
int main()
{
return (0);
}
there is no compilation error, i get an error only when i try to
create an object of the class B. In other words, class B is just an
abstract class. Doesn't the default destructor in B tries to access
the destructor of A and shouldn't that give a compilation error in the
first place, similar to the case where the user provides the
destructor in B?
I was trying to implement a final class and i start having the
destructor of the final class as private,
class A
{
~A()
{
printf("destructor invoked\n");
}
};
class B : public A
{
public : ~B()
{
}
};
int main()
{
return 0;
}
And as expected i get a compilation error, saying "cannot access
private member A::~A declared in A"
But when i change the derived class like the following,
class B : public A
{
}
int main()
{
return (0);
}
there is no compilation error, i get an error only when i try to
create an object of the class B. In other words, class B is just an
abstract class. Doesn't the default destructor in B tries to access
the destructor of A and shouldn't that give a compilation error in the
first place, similar to the case where the user provides the
destructor in B?