Last active
July 27, 2017 11:31
-
-
Save odeblic/706820c998e3410155730149c8b29944 to your computer and use it in GitHub Desktop.
Legal member access violation with polymorphism
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Base | |
{ | |
public: | |
virtual void action() { std::cout << "Base::action()\n"; } | |
}; | |
class Derived : public Base | |
{ | |
private: | |
void action() override { std::cout << "Derived::action()\n"; } | |
}; | |
int main(void) | |
{ | |
Derived derived; | |
Base& base = derived; | |
// derived.action(); // does not build! | |
base.action(); // call the private method! | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment