谁知道这个问题可能是什么原因?

编程入门 行业动态 更新时间:2024-10-19 07:31:05
本文介绍了谁知道这个问题可能是什么原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都知道造成这个问题的原因是什么? ///////////////////////// /////////////////////////////////// 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; 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 *。即使他以某种方式设法将其抨击以使用强制转换进行编译,但他仍然使用包含对象(日期)的大小来设置 。取决于他在列表中省略的其他东西 ,结果可能是灾难性的。

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 someaddress around here. (I saw from DrWatSon log) But it doesn''t happenevery I run the program. Anyone can tell me where this value from ? Isthere 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, danglingpointers 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.

更多推荐

谁知道这个问题可能是什么原因?

本文发布于:2023-11-28 07:03:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:这个问题   谁知道

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!