language: C++ 4.7.2 (gcc-4.7.2)
date: 850 days 16 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
 
using namespace std;
 
class MyClass
{
  private:
    int * a;
    int b;
  public:
    MyClass() { a = new int; }
    ~MyClass() { delete a; }
 
    int & geta(void) const { return *a; } // good?
    int & getb(void) const { return b; }  // obviously bad
};
 
int main() {
        return 0;
}
prog.cpp: In member function ‘int& MyClass::getb() const’:
prog.cpp:15: error: invalid initialization of reference of type ‘int&’ from expression of type ‘const int’