运行此代码时遇到分段错误(没有编译器警告或错误)。尝试将“测试”分配给str->sString
MyClass.cpp
//Constructor
MyClass::MyClass( MyStruct *pDesc )
{
pDesc = new MyStruct();
//This is where I get a segmentation fault
pDesc->bar= 0xFF;
}
MyClass.hpp
class ClGadgetFs
{
public:
struct MyStruct{
int bar;
};
MyClass(MyStruct *pDesc = NULL);
};
我想在调用 new 时我会为结构分配内存?比如malloc(sizeof(myStruct))
我哪里错了?