指针段错误问题...指针段错误问题
我一直在做C++几个星期的同时,但我再次跑到这个问题。
基本上我有这些类给出。我不能改变它们。我先从_ns3__importAuftragResponse kout;
class SOAP_CMAC _ns3__importAuftragResponse
{
public:
ns2__SOAPImportResult *return_;
...
class SOAP_CMAC ns2__SOAPImportResult
{
public:
bool *error;
int *numberOfIgnoreds;
....
的情况下我的代码需要检查的numberOfIgnoreds
第一种方法
ns2__SOAPImportResult* imp_result;
imp_result = kout.return_;
int num;
num = *imp_result->numberOfIgnoreds;
或我使用
ns2__SOAPImportResult imp_result;
imp_result = *(kout.return_);
int* num;
*num = *imp_result.numberOfIgnoreds;
我大多得到分段错误我通常知道在运行时会发生什么但不能拿出正确的颂歌。请帮忙。
编辑
取得进展THX你的答案,谢里夫,但仍需要一些理解
ns2__SOAPImportResult * imp_ptr = new ns2__SOAPImportResult;
imp_ptr = kout.return_;
int * num = new (int);
// next line segfaults
*num = *imp_ptr->numberOfIgnoreds;
什么我很难明白的是,如何或为何的东西是已经分配内存“有”,因为有对象kout的成员return_0
那么说我需要为我分配给它的变量(它是相同类型的过程)分配内存是正确的吗?