Topic: implicit type conversion and function overloading.
Author: "Philip Gruebele" <philipg@bayarea.net>
Date: 1996/10/30 Raw View
Hello,
I would think that the code below should be correct. However, under GNU
gcc 2.7.2 and VC++ 4.2, it gives a compile time error on the first
"getline". Am I misunderstanding something in the standard or do both
these compilers have the same bug?
Regards
Philip Gruebele
////////////////////////////////////////////////////////////////////////////
/////
#include <fstream>
#include <string>
class A
{
public:
inline operator string&(void) {return value;}
protected:
string value;
};
void func(void)
{
A a;
ifstream input("xxx");
getline(input, a); // ERROR 'getline' none of the 2 overloads can
convert parameter 2 from type 'class A'
getline(input, (string&)a); // OK
}
////////////////////////////////////////////////////////////////////////////
//////
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]