Reputation: 5859
My code has structure like this:
file1.cpp
namespace file1
{
...
...
}
int main()
{
file2::func();
}
file2.cpp
namespace file2
{
...
...
}
How will I link file1.cpp with file2.cpp? It throws error that file1.cpp can't find file2 namespace
. I tried adding namespace file2{}
in file1.cpp, but still the same error.
Upvotes: 0
Views: 196
Reputation: 254461
You'll need a header to declare things that are to be accessed from more than one source file:
// file2.h
#pragma once // or a traditional include guard if you prefer
namespace file2 {
void func();
}
Now include this from file1.cpp
to enable the use of file2::func
from there.
// file1.cpp
#include "file1.h"
// ...
Upvotes: 1