c++ 重载运算符问题 在线等

来源:百度知道 编辑:UC知道 时间:2024/05/13 03:29:28
class Mylist
{
public: double mydata;
Mylist *next;
Mylist(double x);
Mylist *operator[](int n);
};
Mylist::Mylist(double x){mydata=x;next=0;}
Mylist Mylist:: *operator[](int n)
{
Mylist * temp=this;
for(int i=0;i<n;i++){temp= temp->next;}
return temp;
}

#include<iostream>

using namespace std;
class Mylist
{
public: double mydata;
Mylist *next;
Mylist(double x);
Mylist *operator[](int n);
};
Mylist::Mylist(double x){mydata=x;next=0;}
Mylist* Mylist:: operator[](int n) //这句,类型写前面
{
Mylist * temp=this;
for(int i=0;i<n;i++){temp= temp->next;}
return temp;
}
int main()
{

return 0;
}