class Class1{
public:
void someFunc(); // This is virtual too in my code, but I don't know if that matters
}
class Class2 : public Class1{
protected:
using Class1::someFunc; // Hiding it cause I don't want it to be used here
}
Class1* obj = new Class2();
obj->someFunc(); // This works, but it's not supposed to, right?
Am I missing something? Why the function gets called? Can I prevent this somehow?
someFunc is a public member of Class1. Line 11 you created a Class1 object. Calling a public member of Class1 is perfectly valid. The fact that it's protected in Class2 is irrelevant.
Had you done the following, you would have gotten an error:
1 2
Class2 * obj2 = new Class2;
obj2->someFunc(); // This should generate an error.