I’m trying to stop class B from accessing DoSomething(Class Y) function and only access DoSomething(Class X) . How can I do that in C++ ?.
Class A {
public:
void DoSomething(Class Y);
}
Class B: public A {
public:
void DoSomething(Class X);
}
You can make
A::DoSomething(Class Y)private, and that’s about the only way you can go about it.Also, you’re not overriding here, but hiding. Still, in
class(yes, it’s lower-case, not upper-case) B, you can still callA::DoSomething().private‘s the only way to deny access.