加载中...
Cplusplus的知识点
发表于:2022-09-29 | 分类: 编程

容器

一些知识点

在C++中子类继承和调用父类的构造函数方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;

class Base
{
public:
Base(int a, int b, int c)
{
m_a = a;
m_b = b;
m_c = c;
cout << "父类的构造函数m_a :" << m_a << endl;
}
public:
int m_a;
int m_b;
int m_c;
};

class Child : public Base
{
public:
//子类继承父类构造方法
using Base::Base;

//子类委托父类构造方法
Child(int a, int b, int c, double d) : Base(a, b, c)
{
m_d = d;
cout << "子类的构造函数m_d :" << m_d << endl;
}

double m_d;
};

int main()
{
//子类继承父类构造方法创建对象
Child ch1(1, 2, 3);
cout << "----------------------------" << endl;
//子类委托父类构造方法创建对象
Child ch(4, 5, 6, 7.7);

return 0;
};

static和new

new一般构造一个对象,需要delate才会析构对象

static声明一个静态数据

for的新特性(c++_11)

1
2
3
4
5
6
7
8
9
10
/**
*@bref 遍历容器
*@pragrm prt 遍历指针
*@pragrm container 需要遍历的容器
*/
for(auto prt: container){
//循环体
}
//第三章遍历方式 利用STL提供遍历算法
for_each(v.begin(), v.end(), myPrint);
上一篇:
vscode相关配置
下一篇:
蓝桥杯问题