feat: 统一 cpp 文件编码格式为 utf-8

This commit is contained in:
tracyxiong1
2023-01-02 20:39:00 +08:00
parent ade7173887
commit 368eda305f
63 changed files with 327 additions and 327 deletions

View File

@@ -24,19 +24,19 @@ int main(){
B b1,*pB;
a1.setA(1);
b1.setA(2);
//把派生类对象赋值给基类对象。
//把派生类对象赋值给基类对象。
a1=b1;
cout<<a1.getA()<<endl;
cout<<b1.getA()<<endl;
a1.setA(10);
cout<<a1.getA()<<endl;
cout<<b1.getA()<<endl;
//把派生类对象的地址赋值给基类指针。
//把派生类对象的地址赋值给基类指针。
pA=&b1;
pA->setA(20);
cout<<pA->getA()<<endl;
cout<<b1.getA()<<endl;
//用派生类对象初始化基类对象的引用。
//用派生类对象初始化基类对象的引用。
A &ra=b1;
ra.setA(30);
cout<<pA->getA()<<endl;

View File

@@ -2,8 +2,8 @@
using namespace std;
/*
先构造成员
再构造自身(调用构造函数)
先构造成员
再构造自身(调用构造函数)
*/
class A {
@@ -33,7 +33,7 @@ int main()
}
/*
执行结果:
执行结果:
Constructing B
Constructing A
Constructing C

View File

@@ -14,7 +14,7 @@ class Derived:public Base{
private:
int y;
public:
Derived(int a,int b):Base(a){ //派生类构造函数的初始化列表
Derived(int a,int b):Base(a){ //派生类构造函数的初始化列表
y=b;
cout<<"Derived constructor y="<<y<<endl;
}

View File

@@ -32,7 +32,7 @@ int main()
}
/*
Ö´ĐĐ˝ášűŁş
执行结果:
Constructing C
Constructing B
Constructing A

View File

@@ -13,7 +13,7 @@ class Line:public Point{
protected:
int len;
public:
Line(int a,int b,int l):Point(a,b) { //构造函数初始化列表
Line(int a,int b,int l):Point(a,b) { //构造函数初始化列表
len=l;
cout<<"Constructing Line,len ..."<<len<<endl;
}

View File

@@ -1,8 +1,8 @@
/*
基类中protected的成员
类内部:可以访问
类的使用者:不能访问
类的派生类成员:可以访问
基类中protected的成员
类内部:可以访问
类的使用者:不能访问
类的派生类成员:可以访问
*/
#include<iostream>
class B
@@ -19,16 +19,16 @@ class D: public B
public:
void f()
{
i=1;//cannot access 派生类不可访问基类私有成员
j=2;//派生类可以访问基类保护成员
i=1;//cannot access 派生类不可访问基类私有成员
j=2;//派生类可以访问基类保护成员
k=3;
}
};
int main()
{
B b;
b.i=1;//cannot access 私有成员,类的使用者不能访问
b.j=2; //cannot access 保护成员,类的使用者不能访问
b.i=1;//cannot access 私有成员,类的使用者不能访问
b.j=2; //cannot access 保护成员,类的使用者不能访问
b.k=3;
system("pause");
return 0;

View File

@@ -1,7 +1,7 @@
/*
派生方式为protected的继承称为保护继承在这种继承方式下
基类的public成员在派生类中会变成protected成员
基类的protected和private成员在派生类中保持原来的访问权限
派生方式为protected的继承称为保护继承在这种继承方式下
基类的public成员在派生类中会变成protected成员
基类的protected和private成员在派生类中保持原来的访问权限
*/
#include <iostream>
using namespace std;
@@ -17,21 +17,21 @@ class Derived:protected Base{
int y;
public:
void sety(int n){ y=n; }
void sety(){ y=getx();} //访问基类的保护成员
void sety(){ y=getx();} //访问基类的保护成员
void showy(){ cout<<y<<endl; }
};
int main(){
Derived obj;
obj.setx(10); //错误
obj.setx(10); //错误
obj.sety(20);
obj.showx(); //错误,
obj.showx(); //错误,
obj.showy();
system("pause");
}
/*
解释:
如最上面文字所示保护继承会将基类的public变为protected而对于protected成员
外部去使用保护成员的时候会报错所以setx与showx访问错误而对于派生类则可直接访问基类的保护成员
在派生类中y=getx()可正常访问!
解释:
如最上面文字所示保护继承会将基类的public变为protected而对于protected成员
外部去使用保护成员的时候会报错所以setx与showx访问错误而对于派生类则可直接访问基类的保护成员
在派生类中y=getx()可正常访问!
*/

View File

@@ -7,7 +7,7 @@ public:
int getx(){ return x; }
void showx() { cout<<x<<endl; }
};
//派生类
//派生类
class derived:public base{
int y;
public:
@@ -16,7 +16,7 @@ public:
void showy()
{ cout<<y<<endl; }
};
//派生类不可直接访问基类的private成员可通过基类的共有成员函数访问
//派生类不可直接访问基类的private成员可通过基类的共有成员函数访问
int main()
{ derived obj;
obj.setx(10);

View File

@@ -22,8 +22,8 @@ public:
};
class ABC:public C, public B {
public:
//虚基类由最终派生类初始化
ABC(int i,int j,int k):C(i),B(j),A(i) //L1这里必须对A进行初始化
//虚基类由最终派生类初始化
ABC(int i,int j,int k):C(i),B(j),A(i) //L1这里必须对A进行初始化
{ cout<<"Constructing ABC..."<<endl; }
};
int main(){

View File

@@ -1,4 +1,4 @@
//ÖØÒª!!!
//重要!!!
#include <iostream>
using namespace std;
class A {

View File

@@ -1,4 +1,4 @@
//当同时存在直接基类和间接基类时,每个派生类只负责其直接基类的构造。
//当同时存在直接基类和间接基类时,每个派生类只负责其直接基类的构造。
#include <iostream>
using namespace std;
class A {