struct product {
int weight;
double price;
} apple, banana, melon;
In thiscase, where object_names are specified, the type name (product) becomes optional: struct requires either a type_name or at least one name in object_names, but not necessarily both.
If the type name is optional, i.e. excluded, then how is the type defined? If I were to write the code as such:
1 2 3 4
struct {
int weight;
double price;
} apple, banana, melon;
then how would I, or anyone reading the code, know that this is a struct of type product?
how would I, or anyone reading the code, know that this is a struct of type product?
There is no type "product" here. apple, banana and lemon are variables of unnamed type.
Before C++11 you could not create any additional variables past this point (in C++11 there are auto and decltype)