1

I'd like to understand why I'm able to declare a pure virtual method in an Interface class, but when implementing it, I could make it private and the compiler doesn't scream.

class I_A {
public:
   void A1 () = 0;
}

class A : public I_A {
private:
    A1();
}

I could even add the 'override' keyword to explicitly indicate that I'm overriding this very method, and still, a successful build.

A related question should be - There isn't any virtue in defining a private method in abstract class. But still, it's possible. what for? and lastly, isn't the visibility of a method (private/public) part of the attributes that suppose to be passed on to its successors?

Yaniv G
  • 307
  • 4
  • 11
  • http://www.gotw.ca/publications/mill18.htm – Evg Jul 30 '20 at 11:38
  • The reason you can do this is because it is allowed in C++? And of course there's a value in having private abstract class methods. After all, methods can be called by other methods of the same class. There is no law that says that methods cannot be called by other methods of the same class, and there's no reason why a private class method, that can only be called by other methods, cannot be abstract. – Sam Varshavchik Jul 30 '20 at 11:42
  • I give up. This seems to be beyond me. (only blaming me, no sarcasm intended, or anything) – Yunnosch Jul 30 '20 at 11:48

0 Answers0