News for hackers. Stuff that matters.
Re:Inheritance Is Terrible by parenthephobia on Saturday March 19, 2016 @07:14PM (#11320942)
I think the important thing isn't what happens internally, but what it looks like from the outside.

Fundamentally, invoking a (non-virtual) superclass's method in C++ doesn't do much more than forward that method to an inner struct.

    struct Reader {
      int fd;
    }

    struct Writer {
      int fd;
      void Write (int) {
        // *this* points to the Writer, not the ReadWriter
      }
    }

    int writeForMe (Writer *w) {
      // *w* points to the Writer, not the ReadWriter
    }

    struct ReadWriter: Reader, Writer {
    }
The only real difference, aside from the syntax, is that in C++ one can dynamically convert a pointer to a Writer that is part of a ReadWriter into a pointer to that ReadWriter, something Go doesn't support.

There are no comments on this comment yet.