C ++ review notes of from 0 to 1 (002)

C ++ class, range resolution operator ::, members of the class member function, the member variable classes, class modifiers

#include <the iostream>
 the using  namespace STD; 

class People 
{ 
    public :
         String name; 
        
    // Member function declared 
    String getName ( void );
     void the setName ( String name); 
 }; 
 
 // Member function defined 
 String People :: getName ( void ) 
 { 
     return name; 
 } 

void People :: the setName ( String yourName) // can not be defined as a name, the name can not be members of the same variable, the other from a required parameter name 
{ 
    name = yourName;
}
 
 int main()
 {
     People p1;
     
     p1.setName("rui");
     string yourName = p1.getName();
     cout << "your name is: " << yourName << endl;
     
     return 0;
 }

 

Guess you like

Origin www.cnblogs.com/mrray1105/p/11220673.html