为什么以下内容不能编译:
void f(int8_t a)
{
}
void f(int16_t a)
{
}
typedef boost::variant<int8_t, int16_t> AttrValue;
int main()
{
AttrValue a;
a = int8_t(1);
f(a);
}
随着编译器错误:
error C2665: 'f' : none of the 2 overloads could convert all the argument types
could be 'void f(int8_t)'
or 'void f(int16_t)'
但是,这没关系:
std::cout << a; // f(a);
std::ostream &operator<<(std::ostream &, const AttrValue &) 在哪里定义以及为什么定义它?