Skip to content

Instantly share code, notes, and snippets.

@kahrl
Last active August 29, 2015 14:06
Show Gist options
  • Save kahrl/cfe7e46cc2ffcdee3cfb to your computer and use it in GitHub Desktop.
Save kahrl/cfe7e46cc2ffcdee3cfb to your computer and use it in GitHub Desktop.
#include <iostream>
class Barney {
int age;
public:
Barney() { age = 42; }
Barney& operator++() {
age++;
std::cout << "Barney is " << age << " years old." << std::endl;
return *this;
}
};
Barney make_barney() {
return Barney();
}
Barney const make_barney_const() {
return Barney();
}
int main(void) {
++make_barney();
//++make_barney_const(); // error: passing ‘const Barney’ as ‘this’ argument of ‘Barney& Barney::operator++()’ discards qualifiers [-fpermissive]
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment