Advertisement
Guest User

doesntcompile

a guest
Sep 11th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. class A
  7. {
  8. public:
  9.  
  10.     A() : _bla(4)
  11.     {
  12.  
  13.     }
  14.  
  15.     const int& operator()(int num1, int num2) const
  16.     {
  17.         return this->at(num1, num2);
  18.     }
  19.  
  20.     int & operator()(int num1, int num2)
  21.     {
  22.         return this->at(num1, num2);
  23.     }
  24. private:
  25.  
  26.     int& at(int num1, int num2) const
  27.     {
  28.         return _bla[num1 + num2];
  29.         // main.cpp:30:26: error: invalid initialization of reference of type ‘int&’ from expression of type ‘const value_type {aka const int}’
  30.     }
  31.  
  32.     vector<int> _bla;
  33. };
  34.  
  35. int main(int argc, char** argv)
  36. {
  37.     A a;
  38.     cout << a(1, 1) << endl;
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement