Re: Frustrated in autocast failure
On 9 Mrz., 03:11, "Old Wolf" <oldw...@inspire.net.nz> wrote:
Here is some simpler code that demonstrates the problem:
#include <iostream>
#include <string>
struct S
{
std::string z;
operator std::string () const { return z; }
// operator int *() const { return 0; }
};
int main()
{
S s;
std::cout << s;
}
The program fails to compile, unless the (int *) line is commented
back in. Perhaps someone more knowledgable than me can now comment
on what is going on.
It seems to me that S->(int *)->(void *) to match ostream::operator<<
(void *) is a trickier sequence than S->std::string to match
operator<<(ostream &, std::string const &) ! In fact the gcc
output shows that the latter function is not even in the candidates
list.
Your observed behaviour is expected: There exists the following
overload
candidates:
1) From <string> we have the function template
template<class charT, class traits, class Allocator>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const basic_string<charT,traits,Allocator>& str);
According to my description given in my answer from
(Mon, 5 Mar 2007 15:55:26 CST) this candidate will be tried,
but since neither a cv-conversion nor a derived-base-relation
(see [temp.deduct.call]) is sufficient to come from the given S to
any
std::basic_string<> this step will fail.
2) Further-on there exists non-template candidates from
the basic_ostream<char> instance std::cout (free function
template candidates also, but they are also not matching),
from which
basic_ostream<char>& basic_ostream<char>::operator<<(const void* p);
is available via exactly one user-conversion and one standard-
conversion.
This conversion sequence is supposed to be tried, see 13.3.1/6,
13.3.3.1/3+4.
I hope this rather abbreviated explanation does not contain
too much fuzziness and incorrectness due to imprecise wording.
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]