结构体中含有类对象,比如下面的例子,是不可以通过把内存空间置零的方式初始化的。
typedef struct{
string nice;
}NICE;
int main()
{
NICE n;
//NICE n = { 0 }; //error
//memset(&n, 0, sizeof(NICE)); //error
n.nice = "ddd";
cout << n.nice.c_str() << endl;
}
结构体中含有类对象,比如下面的例子,是不可以通过把内存空间置零的方式初始化的。
typedef struct{
string nice;
}NICE;
int main()
{
NICE n;
//NICE n = { 0 }; //error
//memset(&n, 0, sizeof(NICE)); //error
n.nice = "ddd";
cout << n.nice.c_str() << endl;
}