class Student {
public:
Student(){}
void display() const{}
friend istream& operator>>(istream& is, Student& s){return is;}
friend ostream& operator<<(ostream& os, const Student& s){return os; }
};
int main()
{
Student st;
cin >> st;
cout << st;
getch();
return 0;
}
friend
키워드를 생략 할 때 연산자가 Student 클래스의 멤버 함수가되도록 시도한 다음 컴파일러에서 "binary 'operator >>' has too many parameters
"을 생성합니다. 모든 멤버 함수가 항상 "this"라는 암시 적 매개 변수를 받기 때문에 (즉 모든 멤버 함수가 private 변수에 액세스 할 수 있기 때문에) 일어난 일부 문서를 읽었습니다. 그 설명을 바탕으로, 나는 다음과 같이 노력했다 :
class Student {
public:
Student(){}
void display() const{}
istream& operator>>(istream& is){return is;}
ostream& operator<<(ostream& os){return os; }
};
int main()
{
Student st;
cin >> st;
cout << st;
getch();
return 0;
}
그리고 "error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'Student' (or there is no acceptable conversion)
"
누구나 내게 명확한 설명을 주시겠습니까?