友元函数重载运算符[]
#include <iostream>#include <string>
using namespace std;
class Array{
int size;
int *date;
public:
Array(int n){
size=n;
date=new int[n];
}
void set(){
for(int i=0;i<size;i++)
cin>>date[i];
}
int* getdate(){
return date;
}
friend int operator[](Array a,int n);
};
int operator[](Array a,int n){
return a.getdate()[n];
}
int main(){
Array a(3);
a.set();
cout<<a[0]<<a[1]<<a[2];
return 0;
}
error C2801: 'operator [' must be a <Unknown> member
求解