Neither of the following programs compile in MSVC++ v 6.0 but both compile, run, and give expected results in Dev-C++. Any explanation for the descrepency? Any suggested corrections to get it to compile with MSVC++?
error message:Code:#include <iostream> using namespace std; class ClassType { public: int f; int s; friend ostream & operator<<(ostream &, ClassType &); }; ostream & operator<<(ostream & os, ClassType & ct) { os << ct.f << ' ' << ct.s << endl; return os; } int main() { ClassType classType; classType.f = 5; classType.s = 89; cout << classType << endl; char ch; cin >> ch; return 0; }
C:\Program Files\Microsoft Visual Studio\MyProjects\mySamples\mySamples.cpp(78) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
and it points to this line in main():
cout << classType << endl;
error message is:Code:#include <iostream> using namespace std; class ClassType { public: int f; int s; friend ClassType operator+(ClassType &, ClassType &); const ClassType & operator=(const ClassType & rhs); }; const ClassType & ClassType::operator =(const ClassType & rhs) { f = rhs.f; s = rhs.s; } ClassType operator+(ClassType & lhs, ClassType & rhs) { ClassType temp; temp.f = lhs.f + rhs.f; temp.s = lhs.s + rhs.s; return temp; } int main(int argc, char* argv[]) { ClassType ct1; ct1.f = 5; ct1.s = 89; ClassType ct2; ct2.f = 6; ct2.s = 11; ClassType ct3; ct3 = ct1 + ct2; cout << ct3.f << ' ' << ct3.s << endl; char ch; cin >> ch; return 0; }
C:\Program Files\Microsoft Visual Studio\MyProjects\mySamples\mySamples.cpp(20) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
and it relates to line:
friend ClassType operator+(const ClassType &, const ClassType &);



LinkBack URL
About LinkBacks



Too bad...MSVC++ 6 is the best I can get for free (legally) Dev-Cpp is pretty darn good compiler though