文章目录
实验背景
本次实验基于Qt Creator下的c++环境,实现了关于类的继承与多态以及矢量图的设计与管理。
注:本次实验需要来回修改类的内部属性与函数,所以只给出测试时的代码,没有精力去保留所有情况,有兴趣的可以书写并保留所有代码,到时候请务必在评论区发给我。(o( ̄▽ ̄)d)
1.类的继承
1.1.继承访问权限测试
1.1.1.public, protected, private属性测试
class CA
{
public:
int a;
void test1(){
a=10;
}
void printf(){
cout<<a<<endl<<b<<endl<<c;
}
protected:
int b;
void test2(){
b=20;
}
private:
int c;
void test3(){
c=30;
}
};
测试类CA的内容
如图所示,test2和test3无法在外部进行访问,只有public可以在外部访问
class CA
{
public:
int a=10;
void test1(){
a=20;
b=40;
c=60;
}
void printf(){
cout<<a<<endl<<b<<endl<<c<<endl;
}
protected:
int b=20;
private:
int c=30;
};
int main()
{
CA a;
a.printf();
a.test1();
a.a