V
Vijay Meena
I am reading c++ Faq and not able to understand this question
properly. The code is like -
// File - decl.hpp
namespace MySubsystem {
class Fred { };
void myFunc(Fred& x) { }
}
//File - main.cpp
#include "decl.hpp"
void myFunc(MySubsystem::Fred& x) { }
int main() {
MySubsystem::Fred x;
myFunc(x) //<---- ambiguous call to this function
}
When I compile it then compiler generates error as ambiguous call to
function myFunc. My question is - why not the call myFunc inside main
bind to the function defined in global namespace. Why is it ambiguous
call ?
If i change the code as follow -
// File - decl.hpp
namespace MySubsystem {
class Fred { };
void myFunc(void) { }
}
//File - main.cpp
#include "decl.hpp"
void myFunc(void) { }
int main() {
MySubsystem::Fred x;
myFunc() //<---- _NO_ ambiguous call here
}
Then I do not get any problem. Why now it binds to function defined in
global namespace ?
Thanks
properly. The code is like -
// File - decl.hpp
namespace MySubsystem {
class Fred { };
void myFunc(Fred& x) { }
}
//File - main.cpp
#include "decl.hpp"
void myFunc(MySubsystem::Fred& x) { }
int main() {
MySubsystem::Fred x;
myFunc(x) //<---- ambiguous call to this function
}
When I compile it then compiler generates error as ambiguous call to
function myFunc. My question is - why not the call myFunc inside main
bind to the function defined in global namespace. Why is it ambiguous
call ?
If i change the code as follow -
// File - decl.hpp
namespace MySubsystem {
class Fred { };
void myFunc(void) { }
}
//File - main.cpp
#include "decl.hpp"
void myFunc(void) { }
int main() {
MySubsystem::Fred x;
myFunc() //<---- _NO_ ambiguous call here
}
Then I do not get any problem. Why now it binds to function defined in
global namespace ?
Thanks