谁知道这个问题可能是什么原因? [英] Anyone knows what can be cause of this problem?

查看:74
本文介绍了谁知道这个问题可能是什么原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道造成这个问题的原因是什么?


///////////////////////// ///////////////////////////////////

typedef struct _date_struct {

int日期,月份,年份;

} date_struct;


课程日期{

私人:

date_struct m_data;

public:

Date& operator =(const Date&);

// ..其他东西

};


日期::〜日期( )

{

FreeStruct(& m_data);

}

日期& Date :: operator =(const Date& SrcDate)

{

FreeStruct(& m_Data);

/// ...

返回* this;

}


void Date :: FreeStruct(Date& lpData)//< - 这里是问题。

{

memset(lpData,0,sizeof(Date));

返回;

}

////////////////////////////////////////// ///////////


我的应用程序崩溃了,因为lpData设置为0x0000014或者这里有一些

地址。 (我从DrWatSon日志中看到)但是每次运行程序都不会发生

。谁能告诉我这个价值来自哪里?

我的代码中有什么问题吗?

解决方案

Aing写道:


////////////////////////////// //////////////////////////////
typedef struct _date_struct {
int date,month,year; <课程日期{
私人:
date_struct m_data;
公开:
日期& operator =(const Date&);
// ..其他东西
};

日期::〜日期()
{
FreeStruct( & m_data);
}
日期& Date :: operator =(const Date& SrcDate)
{
FreeStruct(& m_Data);
/// ...
return * this;
}

void Date :: FreeStruct(Date& lpData)//< - 这就是问题。
{/> memset(lpData,0,sizeof(Date)); <回来;
}
//////////////////////////////////// /////////////////


由于FreeStruct是Date的成员函数,因此无需

传递它可以访问的东西无论如何。还没有

需要从析构函数中调用FreeStruct,因为无论如何都要删除对象

。但这与你的问题无关。

我的应用程序崩溃了,因为lpData设置为0x0000014或者这里的一些
地址。 (我从DrWatSon日志中看到)但是每次运行程序都没有发生。谁能告诉我这个价值来自哪里?我的代码中有什么问题吗?




绝对。但问题出在你代码的其他地方。

你看到的只是症状。注意阵列溢出,悬空

指针等。


-

Karl Heinz Buchegger
kb ****** @ gascad.at



" Karl Heinz Buchegger" < KB ****** @ gascad.at>在消息新闻中写道:40 *************** @ gascad.at ...

>我的应用程序崩溃了,因为lpData在这里设置为0x0000014或一些


地址。 (我从DrWatSon日志中看到)但是每次运行程序都没有发生。谁能告诉我这个价值来自哪里?我的代码中有什么问题吗?



明确地说。但问题出在你代码的其他地方。
你看到的只是症状。注意阵列溢出,悬挂
指针等。




似乎有些混乱。

FreeStruct需要一个日期但是它传递的是date_struct *。即使他以某种方式设法将其抨击以使用强制转换进行编译,但他仍然使用包含对象(日期)的大小来设置

。取决于他在列表中省略的其他东西

,结果可能是灾难性的。


< blockquote>


Ron Natalie写道:

" Karl Heinz Buchegger" < KB ****** @ gascad.at>在消息新闻中写道:40 *************** @ gascad.at ...

我的申请崩溃是因为lpData设置为0x0000014或者这里有一些

地址。 (我从DrWatSon日志中看到)但是每次运行程序都没有发生。谁能告诉我这个价值来自哪里?我的代码中有什么问题吗?



明确地说。但问题出在你代码的其他地方。
你看到的只是症状。注意数组溢出,悬空指针等。



似乎有些混乱。
FreeStruct需要一个Date但它传递的是date_struct *。即使他以某种方式设法将其抨击以使用演员编译,他仍然使用包含对象的大小(日期)来设置
。根据他在课堂上省略的其他东西
,结果可能是灾难性的。




即使他是memsetting他可能会遇到问题的日期。通过memsetting C类型结构进行初始化的原因似乎是一个MS

的东西,它不适用于C ++结构和类所在的地方

可能会破坏vtable指针。


Anyone knows what can be cause of this problem?

////////////////////////////////////////////////////////////
typedef struct _date_struct {
int date,month,year;
}date_struct;

Class Date {
private :
date_struct m_data;
public :
Date& operator=(const Date& );
//.. Other stuff
};

Date::~Date()
{
FreeStruct(&m_data);
}
Date& Date::operator = (const Date& SrcDate)
{
FreeStruct(&m_Data);
///...
return * this;
}

void Date::FreeStruct(Date& lpData) //<- here is the problem.
{
memset(lpData,0,sizeof(Date));
return;
}
/////////////////////////////////////////////////////

My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn''t happen
every I run the program. Anyone can tell me where this value from ? Is
there something wrong in my code?

解决方案

Aing wrote:


Anyone knows what can be cause of this problem?

////////////////////////////////////////////////////////////
typedef struct _date_struct {
int date,month,year;
}date_struct;

Class Date {
private :
date_struct m_data;
public :
Date& operator=(const Date& );
//.. Other stuff
};

Date::~Date()
{
FreeStruct(&m_data);
}
Date& Date::operator = (const Date& SrcDate)
{
FreeStruct(&m_Data);
///...
return * this;
}

void Date::FreeStruct(Date& lpData) //<- here is the problem.
{
memset(lpData,0,sizeof(Date));
return;
}
/////////////////////////////////////////////////////

Since FreeStruct is a member function of Date, there is no need to
pass it something it can access anyway. There is also no
need to call FreeStruct from the destructor, since the object
is going to be deleted anyway. But this is not related to your problem.
My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn''t happen
every I run the program. Anyone can tell me where this value from ? Is
there something wrong in my code?



Definitly. But the problem is located somewhere else in your code.
What you see are just the symptoms. Watch out for array overflows, dangling
pointers etc.

--
Karl Heinz Buchegger
kb******@gascad.at



"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:40***************@gascad.at...

> My application crashed because lpData was set to 0x0000014 or some


address around here. (I saw from DrWatSon log) But it doesn''t happen
every I run the program. Anyone can tell me where this value from ? Is
there something wrong in my code?



Definitly. But the problem is located somewhere else in your code.
What you see are just the symptoms. Watch out for array overflows, dangling
pointers etc.



There seems to be some confusion.
FreeStruct takes a Date but it is passed the date_struct*. Even if he
somehow manages to bash it to compile with a cast, he''s still memsetting
using the size of the containing object (Date). Depending on what "other stuff"
is in the class that he omitted form the listing, the results could be catastrophic.




Ron Natalie wrote:

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:40***************@gascad.at...

My application crashed because lpData was set to 0x0000014 or some

address around here. (I saw from DrWatSon log) But it doesn''t happen
every I run the program. Anyone can tell me where this value from ? Is
there something wrong in my code?



Definitly. But the problem is located somewhere else in your code.
What you see are just the symptoms. Watch out for array overflows, dangling
pointers etc.


There seems to be some confusion.
FreeStruct takes a Date but it is passed the date_struct*. Even if he
somehow manages to bash it to compile with a cast, he''s still memsetting
using the size of the containing object (Date). Depending on what "other stuff"
is in the class that he omitted form the listing, the results could be catastrophic.



Even if he was memsetting Date he''s likely to get into problems. The
idiom of initializing by memsetting C type structures seems to a MS
thing, which doesn''t work with C++ structs and classes where you are
likely to zap the vtable pointer.


这篇关于谁知道这个问题可能是什么原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆