注册 登录
编程论坛 C++教室

用类建立链表出现的问题,求解各位高手?

飘羽 发布于 2011-05-02 02:15, 476 次点击
#include <iostream>
using namespace std;
class list{
    public:
       int data;
       list *next;
       list(){}
      ~list(){}
       static list L[100];
       int length;
};

void creat();
void insert();
void deletelist();
void print();
void creat()
{
    int n;
    int a;
    cin>>a;//输入头结点的数据
    list::L[0].data=a;
    cin>>n;//输入要创建节点的个数
    list::length=n;
    for(int i=0;i<n;i++)
    {
        int b[100];
        list::L[i].next=list::L[i+1];
        cin>>b[i];
        list::L[i+1].data=b[i];
        
    }
}

void print()
{
    for(int i=0;i<list::length;i++)
    {
        cout<<list::L[i].data<<endl;
    }
}

void main()
{
   
    creat();
    print();
}

Compiling...
noname0.cpp
C:\Documents and Settings\魅力元素-Au\Local Settings\Temp\temp232\noname0.cpp(24) : error C2597: illegal reference to data member 'list::length' in a static member function
C:\Documents and Settings\魅力元素-Au\Local Settings\Temp\temp232\noname0.cpp(28) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class list' (or there is no acceptable conversion)
C:\Documents and Settings\魅力元素-Au\Local Settings\Temp\temp232\noname0.cpp(37) : error C2597: illegal reference to data member 'list::length' in a static member function
C:\Documents and Settings\魅力元素-Au\Local Settings\Temp\temp232\noname0.cpp(37) : error C2568: '<' : unable to resolve function overload
Error executing cl.exe.
请问这是什么错误,不懂改啊,请教高手
2 回复
#2
weststreet2011-05-02 11:12
类中怎能包含本类的对象
#3
orrindeng2011-05-02 15:31
static list L[100];
这句话有问题
1