Board index » cppbuilder » Q: why is container use of local struct definitions forbidden as follows?
dhoke
CBuilder Developer |
Q: why is container use of local struct definitions forbidden as follows?2007-04-07 04:01:33 AM cppbuilder49 I know what to do to make the code further below compile. (It doesn't compile as is. It will if I move the definition of somestruct to file scope before the routine.) But why is this considered unacceptable to support? (B/CG [BDS2006] is not the only compiler that dislikes it.) I occasionally have had situations where I did only want a small structure inside some routine's scope for container usage, but am forced to unnaturally move out of that scope to define the item, thus "polluting" the next outer-level scope (be it namespace or file/global), because the compiler complains and refuses to let me do it locally. #include <vector> void routine() { struct somestruct { int a, b ; } ; std::vector<somestruct>v ; int i ; for(i = 0 ; i < 10 ; i++) { somestruct s ; s.a = i ; s.b = i * 2 ; v.push_back( s ) ; } } |