📜  c++ 封装 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:48.625000             🧑  作者: Mango

代码示例1
#include 
using namespace std;

class Employee {
  private:
    // Private attribute
    int salary;

  public:
    // Setter
    void setSalary(int s) {
      salary = s;
    }
    // Getter
    int getSalary() {
      return salary;
    }
};

int main() {
  Employee myObj;
  myObj.setSalary(50000);
  cout << myObj.getSalary();
  return 0;
}