I have the following operators defined in the corresponding namespaces:
namespace literals
{
constexpr ID operator"" _ID(const unsigned long long dyngateID)
{
// ...
// return a constructed id
}
namespace multiplied
{
constexpr ID operator"" _ID(const unsigned long long dyngateID)
{
// ...
// return an id constructed in a specific way
}
} // namespace multiplied
} // namespace literals
In a .cpp file I would like to use both functions, hence I've declared using namespace literals and when I am declaring using namespace multiplied in a concrete function I am getting ambiguous call to overloaded function compile error. How can I differentiate these functions?
Test.cpp
using namespace literals;
void f()
{
// here I am using literals' _ID which is fine
const Type id{1_ID};
}
void g()
{
// here I want to use multiplied's _ID, but obviously I am failing to do so
using namespace multiplied;
const Type id{1_ID};
}
IDobjects._IDin a nested namespace, too. Then in each function you could import the right namespace and no collisions should occur.1'000'000instead of using _ID operator and there won't be any need to avoid any ambiguity.using namespace ...to pull both functions into the same namespace. Either don't dousing namespace literals;in the global namespace (use it at a narrower scope, like inside a function), or talk to your professor (or whoever gave you the assignment) if your requirements analysis, design and implementation are correct.