You can't qualify the namespace for user define literals like
std::cout << 100.0Foo::Qux::_quux << std::endl
But what you can do is use a using statement to import just the literal operator into main using
using Foo::Qux::operator""_quux;
and you would use it like
std::cout << 100.0_quux << std::endl;
You could also call the operator manually like
std::cout << Foo::Qux::operator""_quux(100.) << std::endl;
Another option would be to place your user define literals into a namespace called literals and then you can just import that into main. That would look like
namespace Foo {
class Bar {
public:
Bar(double val): baz(val) {}
// Rest of my object here
private:
double baz;
};
namespace Qux {
inline namespace literals {
Bar operator ""_quux(long double opd) {
return Bar(opd / 10);
}
}
// other Qux Members
}
}
int main() {
using namespace Foo::Qux::literals;
std::cout << 100.0_quux << std::endl;
}
Note that literals is an inline namespace so that Qux can still access the members without additional qualification.
Foo::Qux::operator_quux (100)but that didn't seem to work.operator<<forBaroperator ""in the wild before. Saw it had been added in C++11, but never looked into it. Now that I have, that's a <expletive deleted> to find documentation on. cppreference doesn't even seem to cover it.Foo::Qux::operator""_quux, notFoo::Qux::operator_quux. You can invoke it with that, or you can also dousing Foo::Qux::operator""_quux;to use the literal operator withoutusingthe rest of the namespace.