Member functions of a class in C++ are declared in the class and implemented outside the class

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

The above code declares two member functions in the class, and now they need to be implemented outside the class

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

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

Guess you like

Origin blog.csdn.net/weixin_47414034/article/details/131128143