64,646
社区成员
发帖
与我相关
我的任务
分享
class tt{
public:
int x;
static int &a;
tt() :x(10){}
};
int b = 10;
int &tt::a = b; 为什么这样初始化
char *p = new char[10];
strcpy(p, "asdfasdfasdf");
delete []p;
char p[10];
strcpy(p, "asdfasdfasdf");
char *p = new char[100];
char *pp = new(p) char[10];
strcpy(pp, "asdfasdfasdf");
delete []pp;
! new Tresults in a call ofoperator new(sizeof(T)),
! new(2,f) Tresults in a call ofoperator new(sizeof(T),2,f),
! new T[5]results in a call ofoperator new[](sizeof(T)*5+x), and
! new(2,f) T[5]results in a call ofoperator new[](sizeof(T)*5+y,2,f).
Here, x and y are non-negative unspecified values representing array allocation overhead; the result of the
new-expression will be offset by this amount from the value returned by operator new[]. This over-
head may be applied in all array new-expressions, including those referencing the library function
operator new[](std::size_t, void*) and other placement allocation functions. The amount
of overhead may vary from one invocation ofnewto another. ]
class tt{
public:
int x;
static int &a;
tt() :x(10){}
};
int b = 10;
int &tt::a = b; 为什么这样初始化
//static 必须在外面初始化
char *p = new char[100];//预先分配了100字节的空间
char *pp = new(p) char[10];//在100字节已分配空间上写是不会出现问题的
strcpy(pp, "asdfasdfasdf");
delete []pp;