//.h
#ifndef __POINT_H_
#define __POINT_H_
#include <iostream>
class Point{
private:
int xpos, ypos;
public:
Point(int x=0, int y=0);
friend ostream& operator<<(ostream& os, const Point& pos);
};
#endif
//.cpp
#include <iostream>
#include "Point.h"
using namespace std;
Point::Point(int x, int y) :xpos(x), ypos(y){}
ostream& operator<<(ostream& os, const Point& pos){
os<<'['<<pos.xpos<<", "<<pos.ypos<<']'<<endl;
return os;
}
xpos에 접근에 안됨
operator<< 앞에 스코프는 엇다해쳐먹었냐?
연산자 오버로딩에 스코프를 붙임?
멍탱구리
Point::Point(int x, int y) :xpos(x), ypos(y){}
이건 private 에 접근 했지.
ostream& operator<<(ostream& os, const Point& pos)
이건 접근 못하고 있지.
왜? operator<< 이게 한 둘이냐?
연산자 오버로딩이고 오버라이딩이고 간에 단지 연산자를 함수처럼 쓰는것 뿐인데 클래스의 멤버면 당연히 스코프를 넣어야지.
ostream& Point::operator<<(ostream& os, const Point& pos) 이렇게 바보야
http://dblack.tk
커뮤니티 사이트 입니다 많은 이용 부탁 드립니다.