class X {
// members of class X
};
struct Y {
// members of struct Y
};
union Z {
// members of union Z
};
int main()
{
X xobj; // declare a class object of class type X
Y yobj; // declare a struct object of class type Y
Z zobj; // declare a union object of class type Z
}
struct Y { /* ... */ };
class X { /* ... */ };
int main ()
{
int X; // hides the class name X
Y yobj; // valid
X xobj; // error, class name X is hidden
class X xobj; // valid
}
class S { /* ... */ };
int main()
{
S S,T; // declare two objects of class type S
}
class S { /* ... */ };
int main()
{
S S;
class S T; // keyword class is required
// since variable S hides class type S
}
class S { /* ... */ };
int main()
{
S S;
S T; // error, S class type is hidden
}
class X { /* ... */ };
struct Y { /* ... */ };
union Z { /* ... */ };
int main()
{
X xobj;
X &xref = xobj; // reference to class object of type X
Y *yptr; // pointer to struct object of type Y
Z zarray[10]; // array of 10 union objects of type Z
}
You can initialize classes in external, static, and automatic definitions. The initializer contains an = (equal sign) followed by a brace-enclosed, comma-separated list of values. You do not need to initialize all members of a class.
Objects of class types that are not copy restricted can be assigned, passed as arguments to functions, and returned by functions.