继承对于member布局的影响
- 选择哪些函数作为 inline 函数
- C++ 内存对齐机制
- vptr 放置在 class object 的前端还是尾端?
- 如何存取 shared subobject 内的数据
- vptr 中 functions 的地址偏移
函数相关
函数调用背后的机制
- 堆栈建立
- 参数排列
- 返回地址
- 堆栈清除
- 函数指针
- 函数对象
- 匿名函数 lambda
- c++怎么去生成4096个函数
生成4096个函数,并且保存在一个函数指针数组里面,函数无参返回int,要求通过函数指针数组调用能返回函数在数组中的位置,如fun[50]()就返回50
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
int main(){
vector<function<int(void)>> fun;
for (int i = 0; i != 4096; ++i){
fun.push_back([=]{
return i;
});
}
//test
}
static member functions 特性
- 没有 this 指针
- 不能直接存取其 class 中的nonstatic members
- 不能被声明为 const, volatile 或 virtual
- 不需要经由 class object 调用