using namespace std;
typedef struct __point
{
int xpos;
int ypos;
}point;
point& PntAdder(const point& p1, const point& p2)
{
point *result = new point;
result->xpos = p1.xpos + p2.xpos;
result->ypos = p1.ypos + p2.ypos;
return *result;
}
int main()
{
point *a = new point;
point *b = new point;
a->xpos = 1;
a->ypos = 1;
b->xpos = 3;
b->ypos = 4;
point &c = PntAdder(*a, *b);
cout << c.xpos << endl;
cout << c.ypos << endl;
delete a;
delete b;
delete &c;
return 0;
}
어....그러니까..
변수를 동적할당할때 *a, *b 이렇게 포인터를 붙이는건 왜그런거에요?
자세히 이해하지 못한 채 그냥 규칙처럼 쓰고있어요...
그리고 c는 왜 *가 아니라 &가 붙나요?
마지막으로 point& PntAdder(const point& p1, const point& p2) 에서
PntAdder 랑 p1 이랑 p2에 &가 붙는 이유가 궁금해요
1. malloc 할당 2 . & 는 참조 연산자
* <-- 이거안붙이면 정적할당이 되니깐 ;
뭔 좆 병신이 저렇게 코딩 해놨냐 맞을랴고
dddwj