Computer_IT/C++
Const Member변수 초기화 특성
고급코드
2006. 4. 24. 11:20
반응형
- #include <iostream>
- using namespace std;
- class Student
- {
- const int id;
- int age;
- char name[20];
- public :
- Student(int _id, int _age, char *_name) : id(_id)
- {
- age = _age;
- strcpy(name,_name);
- }
- void Show()
- {
- cout << " " << id << endl;
- cout << " " << age << endl;
- cout << " " << name << endl;
- }
- };
- int main()
- {
- Student st(2002, 20,"good");
- st.Show();
- return 0;
- }
반응형