为什么程序总是在运行时出错

Jun2982804 Jun2982804 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
我在ilist.h中定义了ilist类,并在它的前面声明ilist_item类,然后在它的后面定义ilist_item类
class ilist_item;
class ilist{
public:
ilist() {}
int size();
void insert( ilist_item *ptr, int value );
ilist_item *find( int value );
void display( ostream &os = cout );
void insert_front( int value );
void insert_end( int value );
void remove_front();
void remove_all();
int remove( int value );

private:
ilist( const ilist& );
ilist& operator = ( const ilist& );
void bump_up_size();
void bump_down_size();

int _value;
ilist_item *_next;
ilist_item *_at_front;
ilist_item *_at_end;
int _size;
};

class ilist_item{
public:
ilist_item( int value, ilist_item *item = 0 );
int value() { return _value; }
ilist_item* next() { return _next; }
void next( ilist_item *link ) { _next = link; }
void value( int new_value ) { _value = new_value; }

private:
ilist_item *_next;
int _value;
};

inline ilist_item::ilist_item( int value, ilist_item *item ) : _value( value ){
if( !item ) _next = 0;
else{
_next = item->_next;
item->_next = this;
}
}
在main.cpp中代码如下:
#include "ilist.h"

void main(){
ilist mylist;
}
现在的问题是为什么它总是在运行时exe文件遇到无法处理的异常?
是否因为ilist类与ilist_item类放在同一个文件中?但我试过把它们分开放在不同的文件,但也报错,那我应该怎么改?
...全文
评论 4
收藏 已收藏
分享
返回顶部
Jun2982804
VC/MFC 16,550 成员 421,606 内容