R
Rahul
Hi Everyone,
I was searching for final class in c++, and i came across few links
which suggests to have the constructor of the, to be final class, as
private so that any derived class's constructors can't access the
same.
class C
{
private:
C()
{
printf("in private constructor of C\n");
}
};
class E : public C
{
public: E()
{
}
};
E obj; // causes compile time error saying C() can't be
accessed.
However this just makes class E abstract and doesn't really stop
inheritance from class C. In fact, there isn't any error if i remove
the declaration of obj. Is there any way to avoid extending from C in
the first place?
Thanks in advance!!!
I was searching for final class in c++, and i came across few links
which suggests to have the constructor of the, to be final class, as
private so that any derived class's constructors can't access the
same.
class C
{
private:
C()
{
printf("in private constructor of C\n");
}
};
class E : public C
{
public: E()
{
}
};
E obj; // causes compile time error saying C() can't be
accessed.
However this just makes class E abstract and doesn't really stop
inheritance from class C. In fact, there isn't any error if i remove
the declaration of obj. Is there any way to avoid extending from C in
the first place?
Thanks in advance!!!