Computer_IT/C++

Const Member변수 초기화 특성

고급코드 2006. 4. 24. 11:20
반응형
  1. #include <iostream>
  2. using namespace std;
  3. class Student
  4. {
  5. const int id;
  6. int age;
  7. char name[20];
  8. public :
  9. Student(int _id, int _age, char *_name) : id(_id)
  10. {
  11. age = _age;
  12. strcpy(name,_name);
  13. }
  14. void Show()
  15. {
  16. cout << " " << id << endl;
  17. cout << " " << age << endl;
  18. cout << " " << name << endl;
  19. }
  20. };
  21. int main()
  22. {
  23. Student st(2002, 20,"good");
  24. st.Show();
  25. return 0;
  26. }
 
반응형