struct X { int a; }; struct Y { int a; }; X a1; Y a2; int a3;declares three variables of three different types.
a1 = a2; // error: Y assigned to X a1 = a3; // error: int assigned to Xare type mismatches, and that
int f(X); int f(Y);declare an overloaded function f() and not simply a single function f() twice.
struct S { int a; }; struct S { int a; }; // error: double definitionis ill-formed because it defines S twice.
struct stat { // ... }; stat gstat; // use plain stat to define variable int stat(struct stat*); // redeclare stat as function void f() { struct stat* ps; // struct prefix needed to name struct stat stat(ps); // call stat() }— end example
struct s { int a; }; void g() { struct s; // hide global struct s with a block-scope declaration s* p; // refer to local struct s struct s { char* p; }; // define local struct s struct s; // redeclaration, has no effect }— end example
struct s { int a; }; void g(int s) { struct s* p = new struct s; // global s p->a = s; // parameter s }— end example
class A * A;first specifies A to be the name of a class and then redefines it as the name of a pointer to an object of that class.