Comment 8 for bug 621861

Revision history for this message
Robin Battey (zanfur) wrote :

In c++, structs *are* classes. The only difference between the keywords is that "struct" declares a class that is by default public, where "class" declares a class that is by default private. They share the same namespace even -- the elaborated-type-specifiers mechanism doesn't apply; they're literally classes.

I have Stroustrup in front of me, 12th printing (May 2005), and on page 234, section 10.2.8, it quoth:

  By definition, a struct is a class in which members are by default public; that is,

    struct s { . . .

  is simple shorthand for

    class s { public: . . .

And this short c++ snippet fails to compile with an actually pretty good error message showing this to be the case:

  zanfur@gandalf:~$ cat foo.cpp
  class foo { int bar; };
  struct foo { int bar; };
  zanfur@gandalf:~$ g++ foo.cpp
  foo.cpp:2: error: redefinition of ‘struct foo’
  foo.cpp:1: error: previous definition of ‘struct foo’

I don't see that this bug is valid, at least as written.