In the following scenario, inside function(), on line ss << bb
, I get an error:
binary '<<': no operator found which takes a right-hand operand of type 'CommonType' (or there is no acceptable conversion) error.
My ADL understanding is that it will look into the current namespace (that is AppNamespace::InnerNamespace
) and since no operator <<
is found, it will look into the namespace of the arguments and as the CommonType
is in global namespace I would expect that the operator <<
defined in the CommonTypes.h to be found.
Obviously my understanding is wrong. Can anyone figure out how this should be working?
Main.cpp
namespace AppNamespace
{
typedef std::vector<std::string> OtherType;
std::ostream& operator << (std::ostream& os, const OtherType& ot)
{
for (auto& el : ot)
{
os << el;
}
return os;
}
namespace InnerNamespace
{
void function()
{
CommonType bb;
std::stringstream ss;
ss << bb;
}
}
}
int main()
{
AppNamespace::InnerNamespace::function();
return 0;
}
CommonTypes.h:
#pragma once
#include <vector>
typedef std::vector<uint8_t> CommonType;
std::ostream& operator << (std::ostream& os, const CommonType& bb)
{
for (auto& el : bb)
{
os << el;
}
return os;
}