In C, if we re-declare a variable inside enum, then the compiler throws an error, which "i" is updated as a different kind of character ".It Ok.
#include <stdio.h>
int i = 10;
struct S
{
enum
{
i = 20
}e;
};
int main()
{
printf("%d\n", i);
}
But, in C ++, if we redefine a variable inside enum, then it works fine.
#include <iostream>
using namespace std;
int i = 10;
struct S
{
enum
{
i = 20
}e;
};
int main()
{
cout<<i<<endl;
}
I do not understand why the C ++ compiler does not give an error for the receclaration variable?
source
share