Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <vector>
- using namespace std;
- class A
- {
- public:
- A() : _bla(4)
- {
- }
- const int& operator()(int num1, int num2) const
- {
- return this->at(num1, num2);
- }
- int & operator()(int num1, int num2)
- {
- return this->at(num1, num2);
- }
- private:
- int& at(int num1, int num2) const
- {
- return _bla[num1 + num2];
- // main.cpp:30:26: error: invalid initialization of reference of type ‘int&’ from expression of type ‘const value_type {aka const int}’
- }
- vector<int> _bla;
- };
- int main(int argc, char** argv)
- {
- A a;
- cout << a(1, 1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement