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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:00:52+00:00 2026-06-12T09:00:52+00:00

I am making a static library, everything defined in it is all in one

  • 0

I am making a static library, everything defined in it is all in one namespace. But I am unsure whether I should define the methods as if you would a class, or also wrap them in the namespace. What I’m asking is:

Is this valid:

MyThings.h

namespace MyThings {
    void DoStuff();
    void DoOtherStuff();
}

MyThings.cpp

namespace MyThings {
    void DoStuff() {
        // Do this.
    }

    void DoOtherStuff() {
        // Do that.
    }
}

Or, should I define it like I would class methods?:

MyThings.cpp

void MyThings::DoStuff() {
    // Do this.
}

void MyThings::DoOtherStuff() {
    // Do that.
}

I would prefer not to use using namespace MyThings;, and I would prefer to use my first example if it is valid, I feel it makes the code more readable without having to use MyThings:: before every method identifier.

  • 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-12T09:00:53+00:00Added an answer on June 12, 2026 at 9:00 am

    Both are valid, so you can pick your style according to taste.

    There is an advertised advantage of defining the function using:

    void MyThings::DoStuff() {
        // Do this.
    }
    

    which is that in order to do it, the function must have already been declared. Thus, errors like:

    void MyThings::DoStuf() {
        // Do this.
    }
    

    or

    void MyThings::DoStuff(int i) {
        // Do this.
    }
    

    are caught when you compile MyThings.cpp. If you define

    namespace MyThings {
        void DoStuff(int i) {
            // Do this.
        }
    }
    

    then you generally won’t get an error until someone in another source file tries to call the function, and the linker complains. Obviously if your testing is non-rubbish you’ll catch the error one way or another, but sooner is often better and you might get a better error message out of the compiler than the linker.

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

Sidebar

Related Questions

I'm making a static library product. I want to use ARC but one of
I am making one dynamic library by using some function of libmxml.a library but
I am making static library for the first time and I need to input
Hello i am making an static library for distribution. I am distributing the .h
I was wondering, when making your own static library, is it a good idea
Is there a best practice for making private methods in classes static? I have
I am making an extension method library to use in windows form applications. One
I'm making a static library for distribution for other developers. In other words, a
Basically I am able to create and compile a static library in xcode4 but
So I'm making a static library for iOS. Basically I want people to be

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.