cpp all记录

 10 今天竟然忘记 #define SPLIT_SIZE (5*1024*1024)

define忘记加括号了,造成除法算错误

 

 

9、指针数组和数组指针

具体要看 https://blog.csdn.net/men_wen/article/details/52694069

指针数组  char *arr[4] = {"1a","2a","3a","4a"}; ,也可写成 char *(arr[4]);

数组指针 char (*p) [4];

二维数组的也要结下,to thi

 

 

8、using 用法

a、继承构造函数里

b、类似typedef的功能

    using Ptr = std::shared_ptr<MediaSession>;
    using NotifyConnectedCallback = std::function<void (MediaSessionId sessionId, std::string peer_ip, uint16_t peer_port)> ;
    using NotifyDisconnectedCallback = std::function<void (MediaSessionId sessionId, std::string peer_ip, uint16_t peer_port)> ;

 

7 c++里的struct

https://www.cnblogs.com/zhengfa-af/p/8144786.html

关键点

1、C++的结构体可以包含函数,这样,C++的结构体也具有类的功能,与class不同的是,结构体包含的函数默认为public,而不是private

2、大小(应该只包含数据成员),字节对齐?

 

6 构造函数

https://www.cnblogs.com/shmilxu/p/4849097.html

构造方法用来初始化类的对象,与父类的其它成员不同,它不能被子类继承(子类可以继承父类所有的成员变量和成员方法,但不继承父类的构造方法)。因此,在创建子类对象时,为了初始化从父类继承来的数据成员,系统需要调用其父类的构造方法

 

如果没有显式的构造函数,编译器会给一个默认的构造函数,并且该默认的构造函数仅仅在没有显式地声明构造函数情况下创建。

构造原则见网页

所以继承的时候using 有用

 

 

1、BOOL AddLocalIPToList(std::vector<std::wstring>& a, std::vector<std::wstring>& b);

如果不用引用,则a ,b的值没法返回,要 再queding to thi

2、

    char ch;
    ch = getchar();
    switch(ch){
        case 'X': cout<<'X'<<endl;
        case 'Y': cout<<'Y'<<endl;
        default: cout<<'Z'<<endl;
    }
    

switch要重新结to thi, case 只选择起始点但不自动中断 所以后面要有break

3、

#pragma pack(1)
struct test{
    char x[5];
    char z[5];
    long long y;
};
printf("%d --\n", sizeof(struct test));

结果 20

字节对齐,pragma pack(X),大于x的成员要重新排,不大于的连续排即可

 

4、指针常量 常量指针

指针常量 : int * const p;

常量指针:int const *p;  或者const int *p;

记忆 const修饰左边的,左边没有修饰最近的。

 

5、

#include "stdafx.h"

#include "../new_stdafx.h"
#include "ui_menu.h"

因为ui_menu.h 里用到了"../new_stdafx.h"头文件里的内容,所以两个头文件顺序翻一下就不行了

 6、

虚函数一句话说明:用父类的指针依旧能访问子类的函数.

为什么多态的 析构函数要用虚的:因为不用的话访问不到子类的析构函数。

纯虚函数:基类不用实现

posted @ 2021-11-17 09:33  cnchengv  阅读(148)  评论(0编辑  收藏  举报