Я не могу понять, почему компилятор не может видеть или использовать operator<< ( std::ostream & os, typename A<T>::B const& b )
.
#include <vector>
#include <iostream>
template <typename T>
struct A
{
struct B
{
std::vector<T> innervec;
};
std::vector<B> outervec;
};
template <typename T>
auto operator<< ( std::ostream & os, typename A<T>::B const& b ) -> std::ostream&
{
for (auto e : b.innvervec)
os << "\n\t" << e;
return os;
}
template <typename T>
auto operator<< ( std::ostream & os, A<T> const& a ) -> std::ostream&
{
for (auto e : a.outervec)
os << '\n' << e;
return os;
}
int main()
{
A<int> a;
A<int>::B b1;
A<int>::B b2;
b1.innervec.push_back( 11 );
b1.innervec.push_back( 12 );
b2.innervec.push_back( 21 );
b2.innervec.push_back( 22 );
a.outervec.push_back( b1 );
a.outervec.push_back( b2 );
std::cout << a << std::endl;
}
выдает мне следующую ошибку на VC ++ 15:
error C2679: binary '<<': no operator found which takes a right-hand operand of type 'A<int>::B' (or there is no acceptable conversion)
И он также не компилируется в GCC (хотя пытался только с онлайн-компилятором).
Я полагаю, что здесь задействовано правило о области видимости и дедукции, но я не смог точно выяснить, какой именно.