Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:46:59+00:00 2026-06-11T23:46:59+00:00

Possible Duplicate: “using namespace” in c++ headers I’m a c# developer in the WPF

  • 0

Possible Duplicate:
“using namespace” in c++ headers

I’m a c# developer in the WPF world, but I’ve decided to do all of my Winrt development in C++.

One thing im getting confused over is the use (or not) of using statements in header files (as opposed to typing out the fully qualified type names).

Its so much easier to have using statements in header files. A lot of the Microsoft Winrt samples include using statements in headers which keeps the code clear and easy to read.
However, I’ve been going through the c++ samples in the preview of John Petzolds new book, and he demands that headers be free of all using statements.

I dont understand the pro’s and con’s, and when I google it I get lots of opposing opinions.

Can anyone give me a definitive explanation of this issue as it related to the Winrt world (im not interested in c++ in other environments)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:47:00+00:00Added an answer on June 11, 2026 at 11:47 pm

    In C++, it is very much customary to avoid using namespaces in header files, for several reasons.

    Unlike C#, C++ doesn’t have a nice tidy module system. Anything you do in a header affects every file which includes it. So if one header has a using namespace, if effectively pollutes not just the header file itself, but all files which include it. That can lead to surprising name clashes.

    So in C++, the most common convention is this: never put using namespace in a header. In source files, you can do it if you want to, but many people avoid it even there.

    Another reason is that this can actually aid readability:

    If I refer to a vector<int>, it’s not really clear what that is. It could be any vector class defined anywhere in any of my included headers.

    But if I write std::vector<int>, then I know that this is the standard library header. It tells me where a type comes from. I think that makes the code both clearer and more easy to read.

    Of course, there are tricks you can use to make this more manageable, if you refer to certain types a lot, or if certain namespaces have long, verbose names.

    Long namespace names can be aliased:

    namespace foo = VeryLongNamespaceName; 
    // now I can do foo::bar instead of VeryLongNamespaceName::bar
    

    or individual names can be imported from a namespace:

    using std::cout; 
    // now I can refer to `cout` without the std prefix
    

    Of course, it is not a coincidence that C++ developers tend to use flat namespace hierarchies and short namespace names.

    Nearly all of the C++ standard library is in the std namespace, which is a bit easier to type than the .NET equivalent. (std::vector<T> vs System.Collections.Generic.List<T>). Short names and a flat hierarchy means that you can actually live without using namespace statements.

    Can anyone give me a definitive explanation of this issue as it related to the Winrt world (im not interested in c++ in other environments)

    There is no such thing as “the WinRT world” in this context. If you write C++ code in your WinRT application, then you should follow C++ conventinos and best practices. If you write C# code in your WinRT application, then you should follow C# best practices, and so on.

    Nowhere do WinRT guidelines state “please disregard everything you would normally do in the language you’re using”. WinRT is an API, not a language.

    As for why Microsoft’s samples do otherwise: they’re samples. Their goal is to illustrate specific concepts and give you a starting point, and not to teach you to write good code in general. It is assumed that you can take the concepts they illustrate, and fit it into your own code without copying the various shortcuts taken in the samples. Many samples also omit error handling code for the same reason. It’s irrelevant for the purposes of the sample, but certainly not irrelevant in a real application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I “unuse” a namespace? After declaring using namespace mynamespace, for
Possible Duplicate: How to convert yyyy-MM-dd HH:mm:ss to “15th Apr 2010” using PHP I
Possible Duplicate: “using” keyword in java I'm transitioning from C# to java, so please
Possible Duplicate: “Undefined reference to” template class constructor I've just started using templates, and
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: how to disable javascript errors on “twebbrowser” ? I'm using the TWebBrowser
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript I was using the
Possible Duplicate: Why does gcc have “â” in all its error messages? New to
Possible Duplicate: Do I need to release NSString generated using @“…”? There are two
Possible Duplicate: Create instance of “Class” Using “Reflection” in JavaScript Java has Class.forName(XYZClass) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.