#include <iostream>
#include <array>
using namespace std;
class hsf
{
private:
int x{0};
public:
// hsf()
// {
// x = 0;
// cout << "888888" << endl;
// }
hsf() = default;
hsf(int t) : x(t)
{
cout << this << endl;
cout << "111111" << endl;
}
hsf(int t, int x)
{
cout << this << endl;
cout << "22222" << endl;
}
~hsf()
{
cout << this << endl;
cout << "--------over-----------" << endl;
}
};
int main()
{
// for (size_t i = 0; i < 3; i++)
// {
// int *x = new int(3); //分开的生成每次调用malloc的时候会额外占用多的字节
// cout << x << endl;
// }
auto a = new int[3]{4, 5, 6}; //一次性搞好的a,a+1,a+2是连续的
cout << a << endl;
cout << a + 1 << endl;
cout << a + 2 << endl;
// hsf *mym = new hsf[8]{{1, 2}, 2, 3};
// delete mym;
// auto aaa = new int[5]{1, 2, 3, 4, 5};
// delete aaa;
}
new delete引入allocator
最新推荐文章于 2024-09-10 08:28:20 发布