那位高手帮我看一下重载《错在那里?
// 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;
}
//
#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;
}
...全文
相关推荐
详解Python 函数如何重载?
### 详解Python函数如何实现重载?
java方法重载示例
什么是方法重载?方法重载(Overloading)是指在一个类中可以有多个同名方法,但这些方法的参数列表必须不同。
C++函数重载的深入解析
**避免歧义**:编写重载函数时,要确保不存在导致编译器无法确定调用哪个函数的情况。如果两个或更多函数的参数列表完全相同,编译器会报错。6.
详解C++ 重载运算符和重载函数
C++ 重载运算符和重载函数是编程中的一种高级特性,它允许开发者在同一个作用域内为相同名称的操作提供多种实现方式,从而增加代码的灵活性和表达力。这两种重载主要涉及到函数和运算符的多态性应用。1.
C++ 重载运算符和重载函数
"C++ 重载运算符和重载函数"C++ 语言的一个关键特性是函数重载和运算符重载,这使得程序员能够根据需要定制和扩展语言的功能。函数重载允许在同一个作用域内声明多个同名函数,但每个函数的参数列表必


工具平台和程序库
