为什么程序总是在运行时出错
代码如下:
我在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类放在同一个文件中?但我试过把它们分开放在不同的文件,但也报错,那我应该怎么改?
我在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类放在同一个文件中?但我试过把它们分开放在不同的文件,但也报错,那我应该怎么改?
...全文


