M
MJ_India
struct foo { static const int bar = 0; };
int baz() {
using foo::bar; // [1]
return bar; // [2]
}
[1] is invalid in standard C++ because standard C++ allows _using_
keyword only in 3 ways (For namespace, a member of namespace or in
derived classes to avoid shadowing or to increase privateness of
inherited member)
To make statement [2] work without fully qualified name I need some
workaround(a reference or define).
My question is, what is the advantage of not allowing [1] as valid C++
grammar?
I sometimes think allowing [1] may be useful in some scenarios and
cannot think of a reason why it was decided incorrect. Only advantage
I see here is, it makes compiler implementation little easy (Does it
really? may be.)
But I don't think this is one of the possible answer for my question,
considering C++ complexities. (generic programming etc)
int baz() {
using foo::bar; // [1]
return bar; // [2]
}
[1] is invalid in standard C++ because standard C++ allows _using_
keyword only in 3 ways (For namespace, a member of namespace or in
derived classes to avoid shadowing or to increase privateness of
inherited member)
To make statement [2] work without fully qualified name I need some
workaround(a reference or define).
My question is, what is the advantage of not allowing [1] as valid C++
grammar?
I sometimes think allowing [1] may be useful in some scenarios and
cannot think of a reason why it was decided incorrect. Only advantage
I see here is, it makes compiler implementation little easy (Does it
really? may be.)
But I don't think this is one of the possible answer for my question,
considering C++ complexities. (generic programming etc)