> I don't know the reason either, what I do know is that the rules governing
this kind of thing are extremely complex (try reading the C++ standard)
and often have non-intuitive effects. That is why the advice is to stay
away from obscure corners of the language.
John
You are probably right on that the problem may originate from that fact that
string in itself is an instantiation of a class template because of the need
to instantiate a copy of the overloaded operator << function. I played
around with the code...like the one below:
#include <iostream>
#include <string>
template <typename T>
struct something
{
T x;
operator T(){return x;}
};
template <typename T>
class some_curious_st uff{};
template <typename T, typename OS>
OS& operator << (OS& os, const some_curious_st uff<T>&)
{
return os << "curious stuff";
}
// explicitly instantiate a copy of operator <<
template std::ostream& operator <<(std::ostream &, const
some_curious_st uff<int>&);
/*
Commented out operator overloading below:
if I uncomment the code below and comment out the explicit
instantiation the code gets compiled...
*/
//
//std::ostream& operator << (std::ostream& os, const
some_curious_st uff<int>&)
//{
// return os << "curious int stuff";
//}
int main(void)
{
some_curious_st uff<int> a;
std::cout << a;
something<some_ curious_stuff<i nt> > b;
std::cout << b; // Still ERROR
}
My impression is the explicitly instantiated operator << is not
overloaded....s omehow...
Ben