C++

-> 연산자와 구조체

iIxmont 2017. 9. 14. 00:04

-> 연산자 : 포인터 변수에 의한 항목 선택

예시 : typedef struct __Point

{

int xpos;

int ypos;

}Point;

Point& PntAdder(const Point &p1, const Point &p2)

{

Point *pptr = new Point;   

pptr->xpos = p1.xpos + p2.xpos;

pptr->ypos = p1.ypos + p2.ypos;

return *pptr;

}

구조체 사용

struct Structure {

int a;

char b;

};

struct Structure fors;

fors.a;

fors.b;

예를 들면 C 언어에서는 이렇게 사용 할 수 있다.

C++에서는 struct Structure fors; 문에서 struct를 생략하고 Structure fors;으로 축약하여 사용 할 수 있다.