While the name of a structure must be unique in the set of structures within a namespace, such a name can be "shared" with variables and functions. For example, the following code compiles just fine:
// Code 1
struct h{};
int h{ 8 };
Similarly, there is no collision in:
// Code 2
struct h{};
void h(){}
1) What was the reasoning to allow that name sharing?
Moreover, if we throw templates into the mix, we have some strange situations. The code
// Code 3
template< class H > void h(){}
struct h{};
template< class H > struct j{};
void j(){}
does compile; but the following code fails:
// Code 4
struct h{};
template< class H > void h(){}
void j(){}
template< class H > struct j{};
2) Why the reasoning that allowed code 2 was not good enough to allow code 4? I am not asking about the rules in the standard. I am asking about the reason behind those rules.
Aucun commentaire:
Enregistrer un commentaire