F
frs
See example below: Why does the output of 'a' work and the output of
'b' fails to compile? Is there a way to write class 'something' so that
'b' converts correctly by default? (include iostream, string, use
namespace std)
template <typename T>
struct something {
T x;
operator T();
};
int
main(int, char**)
{
something<int> a;
something<string> b;
a.x = 4711;
b.x = "hello world!";
cout << a << endl; // compiles fine!
cout << b << endl; // operator<< ... no match, compile fails!
}
compiler = gcc 3.3.5
Thanks for any Help.
Frank
'b' fails to compile? Is there a way to write class 'something' so that
'b' converts correctly by default? (include iostream, string, use
namespace std)
template <typename T>
struct something {
T x;
operator T();
};
int
main(int, char**)
{
something<int> a;
something<string> b;
a.x = 4711;
b.x = "hello world!";
cout << a << endl; // compiles fine!
cout << b << endl; // operator<< ... no match, compile fails!
}
compiler = gcc 3.3.5
Thanks for any Help.
Frank