Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement c++ function inside or outside of namespace? [closed]

Tags:

c++

namespaces

I am new to C++ and I want to know what is better/cleaner?

  1. Implementing a function in a namespace
  2. Use the fully qualified name to implement it

e.g:

//foo.h
namespace foo
{
    void bar();
}

1.)

//foo.cpp
namespace foo
{
    void bar()
    {
        //do something
    }
}

or 2.)

//foo.cpp
void foo::bar()
{
    //do something
}
like image 613
Ralf Hintersteininger Avatar asked Mar 08 '23 06:03

Ralf Hintersteininger


1 Answers

There is no difference what-so-ever to the resulting compiled code. It is purely a matter of style.

Use what you like the most (or what is currently the style-in-use of the code base you are working on).

like image 125
Jesper Juhl Avatar answered Apr 29 '23 12:04

Jesper Juhl