3 ms·
> Members of a class in C++ are private by default, but members of a struct are public by default. It's not a bug, it's a feature. The idea is, you should alwa
by 10098 13y ago
> Members of a class in C++ are private by default, but members of a struct are public by default.
It's not a bug, it's a feature. The idea is, you should always prefer private to protected and protected to public (by transitivity, private > public). This is good practice which helps build compact interfaces and maintain encapsulation.
Another reason to use "class" is because it's OOP terminology. There's no notion of "struct" in OOP (in fact, structs shouldn't even be there, they're an atavism).
- nicolasgz 13y ago> you should always prefer private to protected and protected to public It's well known that protected is not any safer than public. Anybody can inherit and use it. You can still make members private in structs. It's only less redundant: class X { public: stuff; private: other stuff; }; vs struct X { stuff; private: other stuff; }; > Another reason to use "class" is because it's OOP terminology. There's no notion of "struct" in OOP That's cargo cult programming. Using "class" doesn't make your code OO. The language we are programming in is C++, not OOP.
- eropple 13y ago> That's cargo cult programming. Using "class" doesn't make your code OO. I shall proceed apace now to call var x = 5; (function() { return x + 2; })(); a glarfblork instead of a lambda, then, if semantics of naming should just be pitched out a window.