fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class classDeclarations
  5. {
  6. private:
  7. int array1[5][5];
  8. public:
  9. classDeclarations(int startValue = 0)
  10. {
  11. for (int i = 0; i < 5; i++)
  12. {
  13. for (int j = 0; j < 5; j++)
  14. {
  15. array1[i][j] = startValue;
  16. }
  17. }
  18. }
  19.  
  20. int* operator[](int index) { return &(array1[index]); }
  21. };
  22.  
  23. int main()
  24. {
  25. classDeclarations myClass;
  26. myClass[0][0] = 5;
  27. cout << (myClass[0])[0] << "\n";
  28.  
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘int* classDeclarations::operator[](int)’:
prog.cpp:20: error: cannot convert ‘int (*)[5]’ to ‘int*’ in return
stdout
Standard output is empty