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 7850785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:58:07+00:00 2026-06-02T18:58:07+00:00

I am writing a library with mutiple dependent modules. When I include a file

  • 0

I am writing a library with mutiple dependent modules. When I include a file from a different module, should I resolve the namespace with:

using namespace project1::namespace1;
class1 obj;

or

typedef project1::namespace1::class1 class1;
class1 obj;

What are the pros/cons of each approach? I read somewhere that we should use typedef in .H files and using in .C files, is this advisable?

One problem I have encountered with ‘typedef’ is it leads to namespace ambiguity if I include both original class and the class with ‘typedef’ in a third module.

  • 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-02T18:58:11+00:00Added an answer on June 2, 2026 at 6:58 pm

    The two options you state are not equivalent. This one:

    using namespace project1::namespace1;
    

    pulls in everything from the namespace, giving you little control and making clashes likely. I see only cons, and no pros here.

    But you don’t need to use a typedef to bring in a single symbol, you can use

    using project1::namespace1::class1;
    

    Whether you use this or the typedef doesn’t make too much of a difference. But bear in mind that typedef is limited to types and enumerations, whereas using can refer to values, functions, etc:

    namespace X {
      const int x{42};
      enum Fruit{Apple, Pear};
    }
    
    using X::x; // OK
    typedef X::x xx; // Error! 'x' in namespace 'X' does not name a type
    

    so the two expressions are not completely equivalent.

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

Sidebar

Related Questions

I'm writing a simple program in Python 2.7 using pycURL library to submit file
I am writing a library which uses a few functions from the windows user32.dll
I have been writing a library for my project (for now I am using
I am writing a library to generate PDF reports using prawn reports. One of
I'm writing a program that is using the functions sin() and cos() from the
I'm using Ruby's EventMachine library for accessing external RESTful APIs asynchronously from a Ruby
I'm writing a win32 library and I need to implement a producer-consumer queue using
I am writing a library that creates multiple elements inside a wrapper element, and
Ok I am writing a library that will be shard between unix and windows.
I'm writing a library for mobile devices. This library notifies the users when certain

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.