Better HN
topnewbestaskshowjobs
Log inSign up

nicolasgz

2 karma · joined Nov 26, 2013 (13y ago) · 9 submissions

Submissions

comment 13y ago · link · parent

> 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.

comment 13y ago · link · parent

Every C++ class declaration ever looks like this:

  class Foo {
  public:
   stuff;
  private:
   other stuff;
  };
What's the point of private-by-default if everybody overrides it anyways?

comment 13y ago · link · parent

> structs are raw data structures while classes are fully featured OOP entities. Don't put they in the same box.

That's not true. Structs and classes are identical except for the minor functional differences highlighted in the article.

comment 13y ago · link · parent

Although it should be possible per standard C++, Microsoft's compilers have trouble dealing with it.

comment 13y ago · link · parent

don't forget the ever-menacing leading underscore!

comment 13y ago · link · parent

Some relevant discussion here:

http://cboard.cprogramming.com/cplusplus-programming/134827-...

comment 13y ago · link · parent

Although I can't currently support my claim, I swear that I have gotten compiler warnings for doing so.

comment 13y ago · link · parent

There are no rules to limit the kinds of member functions you can add to a struct. Structs can be polymorphic, can have vtables, and don't need to be compatible with C.