2 ms·
> Objects just aren't structs with methods on top This view is probably prevalent because C++ more or less does (and did even more in its early days) promote o
by _delirium 17y ago
> Objects just aren't structs with methods on top
This view is probably prevalent because C++ more or less does (and did even more in its early days) promote objects as structs with methods and some other fanciness on top, and C++ was probably the first really widespread OO language.
- vidarh 17y agoIn fact, in C++ structs and classes are the same thing, only struct declarations starts with public visibility by default and class declarations starts with private visibility by default. That's their only difference in C++. And so instances of structs and instances of classes are the same thing in C++ too. You will even sometimes see member functions defined on structs.
- _delirium 17y agoReplying to myself: an interesting aspect, I think, is that this isn't solely a failing of C++ (though C++ has plenty wrong with it). This model of structs-with-methods had already started appearing in C, in the form of APIs built around sets of functions that all operated on the same struct, which was passed as a void* as the first parameter of all the functions (void* for encapsulation purposes); see the pthreads API, for example. So in some ways it's also a consistent, and even sort of naturally arising, model of OO, sort of an organic development out of structured programming, where structs and associated functions serve a main role in the structuring. It's of course a quite different notion of OO from Kay's message-passing, so maybe should have a different name, if it were an ideal world?