So if I initialize a variable of the same type and name within the main function the compiler will complain of the re declaration, for example:
for (int i = 0; i < 5; i++)
{
int a{5};
int a{5}; // error int a previously declared here
}
But there are no errors if I compile this instead:
for (int i = 0; i < 5; i++)
{
int a{5};
}
To my understanding, this looks as if I have initialized "int a" multiple times within the same scope which obviously would cause an error. If somebody could explain what's actually happening it would be greatly appreciated! Thanks!
Aucun commentaire:
Enregistrer un commentaire