问题
Essentially, this is my source code.
namespace name {
int func (void);
}
int main (void) {
name::int func (void) {
//body
}
return 0;
}
Now, I want to write that function, declared int the namespace, in a different place.
回答1:
You can't define the function inside another function like that. There are two options:
Reopen the namespace, and define the function inside it:
namespace name {
int func() {
// body
}
}
Outside the namespace (and also outside any function or class definition), define it using its fully-qualified name:
int name::func() {
// body
}
回答2:
You can't define a function inside a function in C++.
This works
namespace name {
int func (void);
}
int name::func (void) {
//body
}
int main (void) {
return 0;
}
来源:https://stackoverflow.com/questions/5725426/how-does-one-implement-a-function-from-a-namespace