제 첫 번째 질문입니다. 어떤 포맷팅 실수도 곰, 내가 그들을 수정하려고합니다 :) main.cpp | 103 | error : '연산자 <<'에 일치하는 항목이 없습니다 (피연산자 유형이 'std :: ostream {일명 :: basic_ostream <char>}'이고 '사람')
나는 어떤 데이터 타입 X의 최대 세 변수를 찾아 반환이 기능을 가지고있어.
template <class X>
X fmax(X a, X b, X c)
{
X temp=a;
if (b>temp)
temp=b;
if(c>temp)
temp=c;
return temp;
}
그런 다음이
class Person
{
private:
char* name;
int height;
char gender;
public:
Person(){}
Person(char * name,int height, char gender)
{
int sz=strlen(name);
this->name= new char [sz];
strcpy(this->name,name);
this->height=height;
this->gender=gender;
}
void setName(char* name)
{
int sz=strlen(name);
this->name= new char [sz];
strcpy(this->name,name);
}
void setHeight(int h){this->height=h;}
void setGender(char g){this->gender=g;}
char* getName(){return this->name;}
int getHeight(){return this->height;}
char getGender(){return this->gender;}
Person operator= (Person p)
{
int sz=strlen(p.getName());
this->name= new char [sz];
strcpy(this->name,p.getName());
this->height=p.getHeight();
this->gender=p.getGender();
return *this;
}
bool operator> (Person p)
{
if(this->getHeight()>p.getHeight())//The persons should be compared using their heights.
return true;
return false;
}
};
나는 또한 ostream에 과부하처럼 보이는 Person 클래스가 :
ostream &operator<<(ostream &mystream, Person &p)
{
mystream<<"The person's name is: "<<p.getName()<<endl;
mystream<<"The person's height is: "<<p.getHeight()<<endl;
mystream<<"The person's gender is: "<<p.getGender()<<endl;
return mystream;
}
하지만 내 메인에서 오류를 받고 있어요을 :
은int main()
{
Person a("Zacky",178,'m');
Person b("Jimmy",199,'m');
Person c("Matt",200,'m');
Person d=fmax(a,b,c);
cout<<d<<endl;
cout<<fmax(a,b,c);<<endl;//the error strikes here.
return 0;
}
분명히 나는 내가 fmax 함수를 사용하여 초기화했지만 함수에 의해 반환되는 것을 직접 알아낼 수는 없습니다. 내가 뭘 수정해야하는지에 대한 어떤 생각?
P. fmax()
당신이해야 unchangable 를 rvalue를 반환하기 때문에
: 당신은 다음 사항을 변경해야/