0

I searched but I could not find related question. Please correct me if I'm wrong.

In my project I use the following:

using namespace std;
using namespace sf;

I want it to be like below.

using namespace std, sf;

Thanks in advance!

2
  • Write some ugly macros. I wouldn't put myself on that job though. Commented Dec 15, 2018 at 11:42
  • @DeiDei Yeah, that's a horrible idea :P. Commented Dec 15, 2018 at 11:58

2 Answers 2

8

This syntax is not supported, so you'll have to keep declaring multiple using statements.

In general, though, it's considered best practice to avoid declaring using namespace at all - definitely not in headers, and preferably in the inner-most scope possible (as to not pollute too much scope with unwanted symbols.

Sign up to request clarification or add additional context in comments.

Comments

3

I want it to be like below.

using namespace std, sf;

The syntax you're after is simply not supported by the current c++ standard.

Besides it is discouraged to import whole namespaces (at least not in header files), you may sent a request to the c++ standards committee, and see if they like to support that.


The general advice is that you should only

  • either specify exact classes you're using in your translation unit (to save typing) like using std::cout = co;
  • or to make everything clear by explicitly using fully qualified identifiers everywhere like std::cout, std::endl, etc.

The latter way is the most readable and best IMO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.