current position:Home>[C + +] class permissions

[C + +] class permissions

2022-01-26 23:52:19 Pickled cabbage and dried radish

Class permissions

       
       
#include <iostream>
using namespace std;
#include <string>
// Class default private permission
// Default public permission of structure
class Person
{
public:
// Set name
void SetName( string name)
{
p_name = name;
}
// Get name
string GetName()
{
return p_name;
}
// For age
int GetAge()
{
return p_age;
}
// Set lover
void SetLover( string lover)
{
p_lover = lover;
}
private:
string p_name; // Can read but write
int p_age = 18; // read-only
string p_lover; // Just write
protected:


};

int main()
{
Person p;
p. SetName( " Zhang San ");
cout << " full name :" << p. GetName() << endl;
// For age
cout << " Age :" << p. GetAge() << endl;

// Set lover
p. SetLover( " Wang Wu ");
return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.

copyright notice
author[Pickled cabbage and dried radish],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262352174585.html

Random recommended