c++之静态成员的初始化实例介绍

2014-11-24 13:05:55 · 作者: · 浏览: 0
  1. #pragma once
  2. class CStudent
  3. {
  4. public:
  5. CStudent(void);
  6. CStudent(int age,int score);
  7. public:
  8. ~CStudent(void);
  9. public:
  10. int age;
  11. int score;
  12. static int totalScore;
  13. };
  14. #include "StdAfx.h"
  15. #include "Student.h"
  16. CStudent::CStudent(void)
  17. {
  18. }
  19. CStudent::~CStudent(void)
  20. {
  21. }
  22. CStudent::CStudent(int age, int score)
  23. {
  24. this->age=age;
  25. this->score=score;
  26. totalScore =score;
  27. }
  28. int CStudent::totalScore=0;


注意:在类外初始化 这和C#不同