N
Nephi Immortal
Why can’t I put “using namespace name” inside class body?
Why can’t I put “using namespace name” inside class body?
Why can’t I put “using namespace name” inside class body?
Because the Standard prohibits it (in [namespace.udir]). Can you tell
us what might be the purpose? What problem would you solve with that?
Nephi said:Why can’t I put “using namespace name†inside class body?
Because the Standard prohibits it (in [namespace.udir]). Can you tell
us what might be the purpose? What problem would you solve with that?
Well…. It is what I expect….
class name {
using namespace name2;
func1();
func2();
};
instead of …
class name {
name2::func1();
name2::func2();
};
On 2/10/2011 2:34 PM, Nephi Immortal wrote:Because the Standard prohibits it (in [namespace.udir]). Can you tell
us what might be the purpose? What problem would you solve with that?
Well…. It is what I expect….
class name {
using namespace name2;
func1();
func2();
};
instead of …
class name {
name2::func1();
name2::func2();
};
It is much easier rather than placing using namespace name2 inside
each member function’s body or global scope. I hate to add namespace
before member function declaration each time like name2::func1(),
name2::func2(), …..
Why can’t I put “using namespace name” inside class body?
Because the Standard prohibits it (in [namespace.udir]). Can you tell
us what might be the purpose? What problem would you solve with that?
Well…. It is what I expect….
class name {
using namespace name2;
func1();
func2();
};
instead of …
class name {
name2::func1();
name2::func2();
};
It is much easier rather than placing using namespace name2 inside
each member function’s body or global scope. I hate to add namespace
before member function declaration each time like name2::func1(),
name2::func2(), …..
On 2/10/2011 2:34 PM, Nephi Immortal wrote:
Why can’t I put “using namespace name” inside class body?
Because the Standard prohibits it (in [namespace.udir]). Can you tell
us what might be the purpose? What problem would you solve with that?
Well…. It is what I expect….
class name {
using namespace name2;
func1();
func2();
};
instead of …
class name {
name2::func1();
name2::func2();
};
It is much easier rather than placing using namespace name2 inside
each member function’s body or global scope. I hate to add namespace
before member function declaration each time like name2::func1(),
name2::func2(), …..
You can simulate what you want by doing this:
###
namespace RandomName {
using namespace NS;
class C
{
//using namespace NS; // illegal
};
}
using RandomName::C;
###
It's actually useful some of the time, too - particularly when you want
to avoid writing e.g. boost:: a lot in a header (anyone who's familiar
with Boost.Multi-Index may have been annoyed by this sort of thing). You
definitely don't want to writing using namespace boost; in the global
namespace in a header, but you also don't want to write boost:: in front
of everything. A using directive scoped to the class would be ideal, but
it's not allowed.
HTH,
Stu
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.