As comments have pointed out, with what you are trying to do, some compilers might not exactly give the results you are wanting.
If you're merely trying to limit the scope of a struct
or variable type to a limited area (without having to go into another function, etc.), you can just add some extra brackets around your code, ex:
{ // scope start
struct X { int a; char b; };
for(X s = { 0, 'a' } ; s.a < 5 ; ++s.a)
{
std::cout << s.a << " " << s.b << std::endl;
}
} // scope end .. struct X no longer 'visible'
This has the advantage of being more 'readable' as well as have a better chance of 'playing nice' with other compilers.
Hope that helps
Edit:
Even the above code doesn't play well with VS2012, here's what DID work with VS2012 limiting scope:
{ // scope start
struct X { int a; char b; X(int z, char y) : a(z), b(y) {} };
for(X s(0, 'a') ; s.a < 5 ; ++s.a)
{
std::cout << s.a << " " << s.b << std::endl;
}
} // scope end .. struct X no longer 'visible'