melanie93
melanie93

Reputation: 169

C++ namespaces basic usage

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() {}
}

Upvotes: 5

Views: 80

Answers (1)

raven
raven

Reputation: 2564

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

// source file Foo.cpp

#include "Foo.h"

A::Foo::Foo() {}

Upvotes: 7

Related Questions