unnamed namespace

Say I have an unnamed namespace that contains some functions local to a certain file. Is it posable to declare the functions inside of the namespace and define them elseware, or must they be defined inside of the namespace?
ex.
1
2
3
4
5
6
7
8
9
namespace {
    void func();}

int main(){
    func();
    return 0;}

void func(){
    /*code*/}


Is this valid? Is there a valid way of doing it if it isn't?
Thanks
Yes, but like all functions you must respect scope:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace {
    void func();
}

void func(); //this is a different scope (global scope)

int main() {
    func(); //this would print 1
}

namespace {
    void func() {
        std::cout<<1;
    }
}
So I just use the namespace keyword again when defining the function? That makes sense. Thanks!
Topic archived. No new replies allowed.