c++ - Creating a struct and a class with the same name -
summary: happens if declare struct
, class
same name.
details:
i'm reviewing code , saw warning this:
warning: struct 'foo' declared class
when compiling clang there couple of places clang added notes saying:
foo.h:29:1: note: did mean struct here? class foo; ^~~~~ struct
obviously not coding practice have struct , class same name. looks happened developer writing own class , used name in use in file including , did not notice that.
however, question compiler able tell difference between variables declared class foo
, ones struct foo
?
edit:
actually happening developer using class foo
in class bar
had created. think in meantime place class foo
declared had been changed struct bar
. why code compiling. guess answer question struct
, class
interchangeable when declaring objects. still guess it's idea use them consistently.
the keywords struct
, class
largely interchangeable. if write struct foo
, have created class type name of foo
. , name must unique within scope (with special exception reasons of c compatibility, better ignore).