创建空间
#include<stdlib.h>#include<iostream.h>
class shaoyuan{
public:
shaoyuan(int y){ x=y;
cout<<"begin\n";
} void sy(){cout<<"adfasdfas"<<" "<<x<<endl;}
~shaoyuan(){
cout<<"end\n";
}private: int x;
};
void main(){
int *p=(int *)malloc(sizeof(int));
shaoyuan *p1=(shaoyuan*)malloc(sizeof(shaoyuan(10)));
p1->sy(); free (p1);
}
请问为什么在执行shaoyuan *p1=(shaoyuan*)malloc(sizeof(shaoyuan(10)));时不会执行构造函数而且在释放空间的时候也不会执行析构函数,还有就是p1->sy(); 输出的x的值不是10,谢谢!!!