ADL

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::eek:stream &operator<< (std::eek: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::eek: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::eek: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::eek:stream
&A::B::eek:perator <<(std::eek:stream &,const A::B::Struct &)' [found using
argument-dependent lookup]

So the right declaration is found! Why isn't it used?
 
B

Bo Persson

Igor said:
Hello all,

Sometimes I experience strange issue with the ADL (VS9.0 SP1):

// struct.hpp
namespace A
{
namespace B
{
struct Struct {};
std::eek:stream &operator<< (std::eek: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::eek: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::eek: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::eek:stream
&A::B::eek:perator <<(std::eek:stream &,const A::B::Struct &)' [found
using argument-dependent lookup]

So the right declaration is found! Why isn't it used?

There is something fishy about the wchar_t is the messages. You are
not by any chance trying to output to std::wcout?

In that case you would get a best match for wostream in the first
operator, and a best match for Struct in the other.


Bo Persson
 
I

Igor R.

There is something fishy about the wchar_t is the messages. You are
not by any chance trying to output to std::wcout?

Well, actually I try to output neither to cout nor to wcout, but to
the log object of this logging library: http://torjo.com/log2/
In that case you would get a best match for wostream in the first
operator, and a best match for Struct in the other.

Your guess seems to be right, so the problem is somewhere in the
logger template instantiation...

Thanks a lot!
 
I

Igor R.

Solved. It turnes out that the logger template is istantiated for
wostream if UNICODE is defined.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top