那位高手帮我看一下重载《错在那里?

古布 2004-03-05 10:15:10
// List.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using std::cerr;
using std::cout;
using std::ostream;


class List {
friend ostream& operator<<( ostream & os, const List & );
public:
List();
~List();
//List( const List& );
void insert_front( int value );
bool is_empty() const { return front == 0; }
private:
class ListItem {
friend insert_front( int value );
public:
ListItem( int val );// : value( val ), next( 0 ) { }
int value;
ListItem *next;
};
ListItem *front;
ListItem *end;
//list_Item *current;
//int size;
};
friend ostream& operator<<( ostream & os, const List & lc)
{
List::ListItem *pt = 0;

for ( pt = lc.front; pt; pt = pt->next )
os << *pt;
}


List::List() : front( 0 ), end( 0 ) {}
void List::insert_front( int value )
{
ListItem *pt = new ListItem( value );
if ( !is_empty()) {
front = end = pt;
}
else {
pt = front;
front = pt;
}
}
friend ostream& operator<<( ostream& os, const List::ListItem & ic )
{
os << ic.value << "next->";
}
List::ListItem::ListItem( int val )
: value( val ), next( 0 ) { }


int main(int argc, char* argv[])
{
List t1;

t1.insert_front( 3 );
t1.insert_front( 4 );

return 0;
}
...全文
136 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧