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

  • Home
  • SEARCH
  • 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 89577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:44:18+00:00 2026-05-10T22:44:18+00:00

Assuming a class called Bar in a namespace called foo , which syntax do

  • 0

Assuming a class called Bar in a namespace called foo, which syntax do you prefer for your source (.cpp/.cc) file?

namespace foo { ... void Bar::SomeMethod() {     ... }  } // foo 

or

void foo::Bar::SomeMethod() {     ... } 

I use namespaces heavily and prefer the first syntax, but when adding code using the Visual Studio Class Wizard (WM_COMMAND handlers, etc.) the auto-generated code uses the second. Are there any advantages of one syntax over the other?

  • 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. 2026-05-10T22:44:19+00:00Added an answer on May 10, 2026 at 10:44 pm

    I would decline the first (edit : question changed, the first is what i prefer too now). Since it is not clear where Bar refers to from only looking at the function definition. Also, with your first method, slippy errors could show up:

    namespace bar {       struct foo { void f(); }; }  namespace baz {      struct foo { void f(); }; }  using namespace bar; using namespace baz;  void foo::f() { // which foo??  } 

    Because it looks in the current scope (there it is the global scope), it finds two foo’s, and tells you the reference to it is ambiguous.

    Personally i would do it like this:

    namespace foo { void Bar::SomeMethod() {     // something in here } } 

    It’s also not clear from only looking at the definition of SomeMethod to which namespace it belongs, but you have a namespace scope around it and you can easily look it up. Additionally, it is clear now that Bar refers to namespace foo.

    The second way you show would be too much typing for me actually. In addition, the second way can cause confusion among new readers of your code: Is foo the class, and Bar a nested class of it? Or is foo a namespace and Bar the class?

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

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The result you are getting is what would be expected… May 11, 2026 at 11:39 am
  • added an answer Ok, to answer your revised question... There isn't really that… May 11, 2026 at 11:39 am
  • added an answer To follow on to the composition answer - the usual… May 11, 2026 at 11:39 am

Related Questions

Assuming a class called Bar in a namespace called foo , which syntax do
Assuming I have a class A as follows: class A{ int id; int getId(){};
Assuming I have only the class name of a generic as a string in
Assuming one has an abstract base class foo with __get() defined, and a child
Assuming the following class stub: public class Foo<T> { private Class<T> type; public Foo<T>
Assuming a fluid layout is not an option (since that is a different discussion
Assuming a MySQL datastore, when would you NOT want to use memcached in a
Assuming a Read Committed Snapshot transaction isolation setting, is the following statement atomic in
Assuming a table of tags like the stackoverflow question tags: TagID (bigint), QuestionID (bigint),
Assuming a largish template library with around 100 files containing around 100 templates with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.