Is there any way to force the written of a namespace (forbide the use of using namespace) ?

I'd like to forgbide the 'using namespace'.
The idea is to force the written of SPACE::class_or_function.
I have problems to find where I have the funtions and classes and, in adittion, I'm going to read my code better.
Is there any way to do this ?
Thanks
Yes there is:
you can write :
using namespace::class_or_function;
so that when ever you use class_or_function, the compiler will itself attach namespace behind it, but to nothing else.
e.g:
using std::cout;

will enable you to use cout, but not cin (which will have to be std::cin).
Nisheeth, I think what he meant was if there was a way to enforce users of a certain library etc to use the namespace::name syntax instead of using namespace NAMESPACE;

the answer is - no there isn't. And there shouldn't be. If you don't like using namespace - and I'm with you on that - just don't use it. But don't force any particular coding style on your users.
Oh! If that's what he meant, then yes, there is no way t do so.
What I thought, was that he wanted to force the compiler and not another user.
Thanks. Ok.
Something that may work: Instead of a namespace use a class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class MyNamespace
{
public:
    //Add typedefs, static variables and static functions.
    typedef unsigned char MYCHAR;
    static MYCHAR myVar;
    static MYCHAR MyFunction();
};

//I think the above forces people to use those like this:

MyNamespace::MYCHAR someChar = MyNamespace::MyFunction();
if (someChar == MyNamespace::myVar)
{
    //Do stuff.
}
Last edited on
Yeah, but why do that? Getting out of your way just to force people to submit to your idea of good syntax is kinda pointless, don't you think so?
Topic archived. No new replies allowed.