C++中 类的成员函数在类中声明,类外实现

class Student       //定义学生类Student 
{ 
 public:        
   void study();       
   void exam();          
 private:        
   string _name;      
   int _age;       
};

上面的代码在类中声明了两个成员函数,现在需要在类外实现

void Student::study()     //类外实现study()成员函数 
{ 
    cout << "学习C++" << endl; 
} 

void Student::exam()     //类外实现exam()成员函数 
{ 
    cout << "C++考试成绩100分" << endl; 
}

猜你喜欢

转载自blog.csdn.net/weixin_47414034/article/details/131128143