c++中访问私有属性
在c++的类中,属性通常有三种类型,public、private、protected,下面以员工介绍类作为案例理解。
具体实现
#include<iostream>
using std::string;
class Employee{
public:
string Name;
string Company;
int Age;
void IntroduceYourself(){
std::cout << "Name - " << Name << std::endl;
std::cout << "Company - " << Company << std::endl;
std::cout << "Age - " << Age << std::endl;
}
Employee(string name,string company, int age){
Name <