// 111.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
class person
{
int age;
public:
void SetAge(int nAge)
{
age = nAge;
}
int GetAge()
{
return age;
}
};
class student : public person
{
public:
void display()
{
using namespace std;
cout<<person::GetAge();
}
void SetAge(int nAge)
{
// age = nAge; //error
}
};
int main(int argc, char* argv[])
{
student stu;
stu.person::SetAge(25);
stu.display();
return 0;
}
子类无权访问父类的私有数据成员
最新推荐文章于 2024-05-17 11:29:58 发布