Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to revert back to "default" global namespace?

Basically, I am working with some provided header files with the following format:

#include <iostream>

using namespace std;

class bar
{
public:
    void printSomething(void)
    {
        cout << "This is an example." << endl;
    }
}

My question is, since I can't modify the provided header, how do I strip the std namespace in my files and go back to the default global namespace? I have tried "using namespace ::;" and "using namespace ;", but the the compiler isn't happy with either of those. Any ideas on how to force a clean slate with namespaces?

like image 662
eestrada Avatar asked Oct 26 '25 10:10

eestrada


1 Answers

You can't. That's why the using namespace clause is so evul. You could include those headers inside another namespace though:

namespace bleh {
    #include "library_that_uses_evul_using_namespace.h"
}

That will pollute only the bleh namespace.

like image 106
mfontanini Avatar answered Oct 29 '25 01:10

mfontanini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!