Normally, one could write a conversion operator to convert to another class like
struct A {};
struct B
{
operator A()
{
return A();
}
};
Now, what if A
struct has a namespace different than B
:
namespace mars {
struct A {};
}
namespace jupiter {
struct B
{
operator A() //??
{
return A();
}
};
}
What should the operator A()
statement become?
You can simply fully qualify the names
namespace mars {
struct A {};
}
namespace jupiter {
struct B
{
operator mars::A()
{
return mars::A();
}
};
}
As a suggestion: try not to do something like
using namespace mars;
in the global scope: that would pollute it and render things more complex when the application grows (e.g. name clashing). Especially for the std
namespace, it is often more desirable to fully qualify names to avoid this phenomenon.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments