Hello , when I try to compile the following code the compiler gives me the following error :
error C2804: binary 'operator <<' has too many parameters
the code makes no sense , I just wanted to learn how to use the overloading with any kind of program. Here is the code :
Thank you.Code:#include <iomanip> #include <iostream> #include <ostream> #include <fstream> #include <string> using namespace std; class name{ public: void display(void); void assing(string t1,string t2); ostream & operator<< (ostream &k , name &obj){ k<<obj.d1<<obj.d2<<endl; } private: string d1,d2,d3; }; void name::assing(string t1,string t2){ d1=t1; d2=t2; } void name::display(void){ cout<<d1<<endl<<endl; cout<<d2<<endl<<endl; } int main(){ string s1="aaa", s2="bbbb"; name c; c.assing(s1,s2); cout<<c; return 0; }



LinkBack URL
About LinkBacks


