News for hackers. Stuff that matters.
Re:C++ is a hack by usefulcat on Tuesday February 16, 2016 @12:12PM (#11111353)
"[C++] actually allows subclasses to hide public methods from the superclass."

That one doesn't even make sense. A base class (superclass) in C++ never knows anything about any of its descendants. So it can only ever know about methods declared in the base class, and what their visibility is in the base class. Secondly, it's true that a derived class could (for example) override a public base class method and make it private in the derived class, but that won't change the ability of the base class to call that method.

Re:C++ is a hack by lfowles on Tuesday February 16, 2016 @12:43PM (#11111632)
I actually tested this one since I had never encountered it in the wild. You can indeed call and get the expected results from the derived classes (now private) member function.
Re:C++ is a hack by slavik81 on Tuesday February 16, 2016 @08:48PM (#11114586)
Just to be clear, that's not in conflict with what the author claimed. You can't call that method using a pointer to the derived class. That would be an access violation, because it was declared private. You need to use a pointer of the superclass type.

    struct I_A {
      virtual void foo() {}
    };
    
    struct A : I_A {
    private:
      virtual void foo() {}
    };
    
    int main() {
      A a;
      // a.foo(); // compile error
      I_A& ia = a;
      ia.foo();   // ok
    }

To be honest, I find this behaviour useful so it doesn't upset me. It's a decent way to mark off functions that you needed to implement to satisfy an internal interface as not-for-users.
Re:C++ is a hack by lfowles on Wednesday February 17, 2016 @12:09AM (#11115476)
Question: Is struct inheritance public by default?
Re:C++ is a hack by slavik81 on Wednesday February 17, 2016 @01:36AM (#11115807)
Yes. If A were a class, I'd have to specify `public I_A`, but since it's a struct, that's the default.
Re:C++ is a hack by slavik81 on Tuesday February 16, 2016 @12:33PM (#11111545)
You misunderstood. When the author wrote "from the superclass" they were trying to say "declared on the superclass". It has since been updated to be clearer.
Re:C++ is a hack by nikbackm on Tuesday February 16, 2016 @12:15PM (#11111382)
It's a bit like an explicit interface implementation in C#.
Re:C++ is a hack by rootlocus on Tuesday February 16, 2016 @12:18PM (#11111418)
The base class is not the only client of that method.
Re:C++ is a hack by usefulcat on Tuesday February 16, 2016 @12:22PM (#11111463)
True, but it specifically says "hide public methods from the superclass".
Re:C++ is a hack by softawre on Tuesday February 16, 2016 @12:27PM (#11111502)
Oh, I get it. I think s/from/of is what was meant.