c++ cout ... ostream& 에 관한 질문 간단한 내용입니다.
글쓴이: gyxor / 작성시간: 일, 2003/05/11 - 9:06오후
#include<iostream>
using namespace std;
class tri {
private :
int x;
int y;
public :
tri (int a,int b);
friend ostream& operator<< (ostream& os,tri m);
};
tri:: tri (int a,int b)
{
x = a;
y = b;
}
ostream& operator<< (ostream& os,tri m)
{
os <<"x= "<< m.x << " y = " <<m.y << endl ;
return os;
}
void main()
{
tri a(10,20);
tri b(30,40);
cout << a << b;
}
/*
friend ostream& operator<< (ostream& os,const tri &m);
아래와 같이 고치면 왜 에러가 나는 것인지 궁금합니다.
friend ostream operator<< (ostream& os,const tri &m);
friend ostream& operator<< (ostream os,const tri &m);
ostream 객체는 무조건 참조로 선언해야하고 복사할수 없기 때문인가요?
답변부탁드립니다.
*/
Forums:


[code:1]int foo(int &i);int fo
위 두 함수는 구별할 수 없습니다. function overloading을 쓰려면 함수가 구별가능(인자값이 타입이 달라야함)해야 하는데, reference로 선언된 것들은 non-reference로 선언된 것과 호출 시 구별할 수 없기 때문입니다.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://cinsk.github.io/cfaqs/
댓글 달기