0

I found a piece of code that uses the following statement:

using flags = std::ios_base::fmtflags;
flags fl = std::ios_base::dec;

This is the first time that I encountered it. How can you use a namespace as a type.

2
  • 2
    It's not a namespace, its a type alias Commented May 12, 2017 at 20:09
  • using namespace and using other_stuff are different. You can read them as plain English to understand the meaning. Commented May 12, 2017 at 20:13

2 Answers 2

5

You seem to be confusing type aliasing with using declerations. Type aliasing behaves like a typedef, it defines another name for an existing type. Your example is equivalent to the following :

typedef std::ios_base::fmtflags flags;
flags fl = std::ios_base::dec;
Sign up to request clarification or add additional context in comments.

2 Comments

@SergeyA using can be templated.
Than it becomes alias template, not type alias.
3

Nobody uses a namespace as a type in this snippet. std::ios_base::fmtflags is a type, not a namespace, and this using flags = std::ios_base::fmtflags; line just introduces an alias to it.

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.