#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
using namespace std;
//new 和delete的基本语法
//和c语言的 malloc free 类似
//分配基础类型变量 分配数组变量 分配类对象
class C
{
private:
public:
C (int a)
{
}
~C()
{
}
};
int main()
{
int *a=(int *)malloc(sizeof(int));
free(a);
int *a1=new int;
delete a1;
int *b=(int *)malloc(sizeof(int)*10);
free (b);
int *b1=new int[10];
delete []b1;
C *c=(C *)malloc(sizeof(C));
free (c);
C *c1=new C(10); //new能执行类的构造函数
delete c1; //delete能执行类的析构函数
system("pause");
return 0;
}
c++学习记录_03.01
最新推荐文章于 2024-04-18 21:50:03 发布