尝试着自己写一点练习,但母语为Java的我对于C++似乎还是有点不适应
还是很微妙呀,例如容器在堆上的行为,在栈上的行为,混合时的行为,delete的行为等
做了个研究,写了点代码,不过其中还是有点疑惑
当一个对象放在栈上的时候,对象包含的vector对象会只保留一个地址,这个地址指向一个与堆/栈均不同的位置。
这个位置在哪里?已知的是比堆要高很多
上代码
1
#ifndef PERSON_H
2
#define PERSON_H
3
4
#include <iostream>
5
#include <string>
6
#include <vector>
7
8
using namespace std;
9
10
class Person
11
#endif
2
3
4
5
6
7
8
9
10
11
1
#include "Person.h"
2
#include <cstring>
3
#include <sstream>
4
5
6
Person::Person(string name,int size)
7
}
2
3
4
5
6
7