Last active
August 29, 2015 14:06
-
-
Save kahrl/cfe7e46cc2ffcdee3cfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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