why is cout giving an error?
I am trying to write a code for making copy constructor in C++. I have made a function print() that basically prints the data members of my class String. But whenever I call that function in my constructor body, my compiler gives an error saying " no match for 'operator <<'. I don't understand why that is the case. Could someone kindly help? Thanks!! #include <cstdlib> using namespace std ; class String { char *str_ ; int len_ ; public: void print() // print function { cout<<"str_ = "<<str_<<"\t"<<"len_ = "<<len_<<endl ; } String(const char* str): str_(strdup(str)), len_(strlen(str_)) // constructor { cout<<"Ctor called "<< print()<<endl ; } String() {} // default constructor String(const String&obj): str_(strdup(obj.str_)), len_(obj.len_) // copy constructor { cout<<"Copy Ctor called :"<<print()<<endl ; } String& operator = (String& obj) // operator oveloading { free(str_) ; str_ = strdup(obj.str_) ; len_ = obj.len_ ; return *this ; } ~String() // destructor { free(str_); cout<<"Dtor called " ; <<print()<<endl ; } }; int main() { String s1("yusha"), s2= "arif" ;