Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ namespaces basic usage

Tags:

c++

namespaces

In the example below, is it necessary to use namespace A{} in the source file or is it redundant as it is already been done in the header file?

// header file Foo.h

namespace A
{
    class Foo
    {
        Foo();
    };
}

// source file Foo.cpp

#include "Foo.h"

namespace A
{
    Foo::Foo() {}
}
like image 595
melanie93 Avatar asked Nov 20 '19 19:11

melanie93


1 Answers

It's necessary, but you can do the following instead:

// source file Foo.cpp

#include "Foo.h"

A::Foo::Foo() {}
like image 105
raven Avatar answered Oct 01 '22 18:10

raven