I
Igor R.
Hello all,
Sometimes I experience strange issue with the ADL (VS9.0 SP1):
// struct.hpp
namespace A
{
namespace B
{
struct Struct {};
std:stream &operator<< (std:stream &os, const Struct &s);
}
}
//.....
// outputter.hpp
namespace A
{
template<class T> class Outputter
{
//...
void f()
{
B::Struct s;
std::cout << s;
}
};
At some other place, where template Outputter is instantiated, I've
got the compiler error:
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'A::B::Struct' (or there is no acceptable conversion)
I would think that the operator is really undeclared yet at the point
of the template instantiation, but:
1) it's declared just after A::B::Struct, so if the compiler does see
Struct it should see operator << as well
2) next error lines state:
2> c:\program files\microsoft visual studio 9.0\vc\include
\ostream(653): could be 'std::basic_ostream<_Elem,_Traits>
&std:perator <<<wchar_t,std::char_traits<wchar_t>>
(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using
argument-dependent lookup]
2> with
2> [
2> _Elem=wchar_t,
2> _Traits=std::char_traits<wchar_t>
2> ]
2> c:\program files\microsoft visual studio 9.0\vc\include
\ostream(700): or 'std::basic_ostream<_Elem,_Traits>
&std:perator <<<wchar_t,std::char_traits<wchar_t>>
(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-
dependent lookup]
2> with
2> [
2> _Elem=wchar_t,
2> _Traits=std::char_traits<wchar_t>
2> ]
2> d:\myproject\struct.hpp(471): or 'std:stream
&A::B:perator <<(std:stream &,const A::B::Struct &)' [found using
argument-dependent lookup]
So the right declaration is found! Why isn't it used?
Sometimes I experience strange issue with the ADL (VS9.0 SP1):
// struct.hpp
namespace A
{
namespace B
{
struct Struct {};
std:stream &operator<< (std:stream &os, const Struct &s);
}
}
//.....
// outputter.hpp
namespace A
{
template<class T> class Outputter
{
//...
void f()
{
B::Struct s;
std::cout << s;
}
};
At some other place, where template Outputter is instantiated, I've
got the compiler error:
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'A::B::Struct' (or there is no acceptable conversion)
I would think that the operator is really undeclared yet at the point
of the template instantiation, but:
1) it's declared just after A::B::Struct, so if the compiler does see
Struct it should see operator << as well
2) next error lines state:
2> c:\program files\microsoft visual studio 9.0\vc\include
\ostream(653): could be 'std::basic_ostream<_Elem,_Traits>
&std:perator <<<wchar_t,std::char_traits<wchar_t>>
(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using
argument-dependent lookup]
2> with
2> [
2> _Elem=wchar_t,
2> _Traits=std::char_traits<wchar_t>
2> ]
2> c:\program files\microsoft visual studio 9.0\vc\include
\ostream(700): or 'std::basic_ostream<_Elem,_Traits>
&std:perator <<<wchar_t,std::char_traits<wchar_t>>
(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-
dependent lookup]
2> with
2> [
2> _Elem=wchar_t,
2> _Traits=std::char_traits<wchar_t>
2> ]
2> d:\myproject\struct.hpp(471): or 'std:stream
&A::B:perator <<(std:stream &,const A::B::Struct &)' [found using
argument-dependent lookup]
So the right declaration is found! Why isn't it used?