Reputation: 3381
A small example to reproduce the error in Visual Studio (Community) 2022:
#include <iostream>
#include <memory>
class Base {
public:
virtual void b();
protected:
std::string Method() {
return "Base::Method";
}
};
class SubA : public Base {
public:
// Prevent compiler from optimizing class away.
int doSomething() {
return 7;
}
};
int main() {
SubA sa;
sa.doSomething();
sa.Method(); // <-- Function is inaccessible.
}
Why is the error? The inheritance is public and I'm calling Method
on an object from the SubA
class.
Upvotes: 0
Views: 57
Reputation: 238341
The inheritance is public
But the member function is protected. You're accessing the member function from main
which is outside of the scope of the class or its decendants, so it has no access to protected member functions.
Upvotes: 2