M
mshetty
Hi,
I have a class x with two public methods xmethod1 and xmethod2. I want
to derive a class y such that it can access only xmethod2. I have done
the following and it compiles please let me know if it is valid to do
so.
class y : public x
{
private:
void xmethod1()
{
// some dummy implementation
// trying to override xmethod1 with a private access
// specifier so that whenever xmethod1 is invoked using an
// object of y an error is thrown by the compiler
}
}
Is this valid? I want the compiler to throw an error.
Is there a better way of doing this?
Thanks and Regards,
M Shetty
PS: This still allows:
y *y1 = new y;
x *x2 = y1;
x2->xmethod1();
// calls derived private method y::xmethod1
I have a class x with two public methods xmethod1 and xmethod2. I want
to derive a class y such that it can access only xmethod2. I have done
the following and it compiles please let me know if it is valid to do
so.
class y : public x
{
private:
void xmethod1()
{
// some dummy implementation
// trying to override xmethod1 with a private access
// specifier so that whenever xmethod1 is invoked using an
// object of y an error is thrown by the compiler
}
}
Is this valid? I want the compiler to throw an error.
Is there a better way of doing this?
Thanks and Regards,
M Shetty
PS: This still allows:
y *y1 = new y;
x *x2 = y1;
x2->xmethod1();
// calls derived private method y::xmethod1