Yep, but it's a pointer of type Interface that actually points to a Derived object. Thus, the code is executing a private method from outside the class.
I would expect at least a warning from the compiler.
Think at this scenario... You defined the interface with the public pure-virtual method, and then the derived class
"Derived1" which implement that method as
public. Few derived classes after, ad example in
"Derived4" you forgot about the interface and defined a
private method with the same name, which reads the private member "value" (I know this is stupid for a Get method, but it could be anything else. It's just to keep the example consistent with the posted code).
Then you deliver the library to the user and teach him to use the interface to access the method in "Derived1". A lucky user could, by chance, find out that with something like
|
Interface *ptr = new Derived4(5);
|
he can get access to that private member "value" that you thought to be private.
I confirm that it seems to me a possible-yet-lucky way to access a private member you are meant not to access...