Search code examples
c++namespacesextern

calling extern function without specify namespace


The code compile without error, I would like to know what's the different declaring extern function within and without namespace?

--a.h--

namespace mynamespace {
    extern void foo();
}

--a.c--

namespace mynamespace {
    void foo(){
        dosomething;
    };
}

Are there any concern that I should worry about when calling foo() without specifying namespace?

#include "a.h"
int main(int argc char *argv )
    foo()
}

instead of

#include "a.h"
int main(int argc char *argv )
    mynamespace::foo();
}

Solution

  • It turns out that using namespace mynamespace; is already declared in other header file. So if one file include header file, which have already defined using namespace mynamespace;, the current header file will also affected.