#include<iostream>
#include<cstring>
using namespace std;
class data{
private:
char value[100];
public:
data(char *val){ //생성자는 char* 자료형만 받는다.
strcpy(value,val); //하지만 메인에서 data b를 선언하는곳을 보면
}
void output(){
cout<<value<<endl;
}
};
int main(){
data a("somebody help me");
data b(a); //char* 자료형을 넣은것이 아니라, data 객체를 넣었다.
a.output();
b.output();
return 0;
}
(자기 자신과 같은 형태의 객체를 받는것을 복사 생성자라고 한다.)
'study > C/C++' 카테고리의 다른 글
포인터 변수와 주소 (0) | 2013.01.29 |
---|---|
c++ string 함수 구현 (0) | 2013.01.25 |
동적할당된 다중(이중) 포인터를 인자로 함수 호출 (0) | 2013.01.23 |
이중포인터 동적할당?!? (0) | 2013.01.22 |
c++ 연산자,자료형 (0) | 2012.12.20 |