#include <iostream>
using namespace std;
class a{
public:
double& operator[](int index);
double get(int index);//returns value at required index.
private:
double array[20];
};
double& a::operator[](int index){
return array[index];
}
double a::get(int index){
return array[index];
}
void main(){
a obj;
obj[5] = 4;
cout << "obj[5] = " << obj.get(5) << endl;
double var = obj[5];
cout << "var = " << var << endl;
}
No comments:
Post a Comment