생성자를 추가했다. 객체 생성시 a = 8로 b=10으로 초기화 된다.
----------------------
class CS{
public:
int a, b;
CS(){
a = 8;
b = 10;
}
void swap()
{
int temp;
temp = a;
a=b;
b =temp;
}
};
-----------
#include <stdio.h>
#include "CS3.h"
int main()
{
CS cs1;
cs1.swap();
printf("a=%d, b=%d\n", cs1.a, cs1.b);
return 0;
}
댓글 없음:
댓글 쓰기