Advertisement
Masfiq

Array subscript operator

Dec 8th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. /* masfiq 8th december, 2016*/
  2.  
  3.  
  4. #include<iostream>
  5. #include<cstring>
  6. #include<cstdlib>
  7. using namespace std;
  8.  
  9. class Demo{
  10.     int a[];
  11. public :
  12.     int& operator [] (int idx){
  13.         return a[idx];
  14.     }
  15. };
  16.  
  17. int main(){
  18.     Demo demo;
  19.     demo[2] = 10;
  20.     cout<<demo[2];
  21.  
  22. }
  23. output :
  24. 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement