سلام دوستان من کد زیر را نوشتم که از خط زیر ایراد می گیرد
ostream& String::operator<<(ostream& stream,const String& str){
کل کد
#include <iostream>
#include <cstring>
using std::cout;
using std::cin;
using std::endl;
using std::ostream;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class String{
char *ch;
public:
String();
String operator=(char* ob);
String operator+(String str);
char * toString();
friend ostream& operator<<(ostream& stream,const String& str);
};
String::String(){
}
String String::operator=(char* ob){
ch=ob;
return *this;
}
String String::operator+(String str){
String temp;
temp.ch=strcpy(ch,str.ch);
return temp;
}
ostream& String::operator<<(ostream& stream,const String& str){
stream<<str.ch;
return stream;
}
char * String::toString(){
return ch;
}
int main(int argc, char *argv[]) {
String str1,str2,str3;
str1="ehsan";
str2="shahbakhty";
cout<<str2;
return 0;
}
خطای زیر تولید می شود :
[Error] 'std::ostream& String::operator<<(std::ostream&, const String&)' must take exactly one argument