make some methods const

master
neingeist 11 years ago
parent 9092970b7d
commit 86c0368a04

@ -9,7 +9,7 @@
int myfunction (int x, int y) { return x+2*y; }
struct myclass {
int operator()(int x, int y) { return x+3*y; }
int operator()(int x, int y) const { return x+3*y; }
} myobject;
int main() {

@ -4,7 +4,7 @@
class Animal {
public:
// Note: using *virtual* does the difference here!
virtual void makeSound() {
virtual void makeSound() const {
std::cout << "<generic animal sound> from " << this << std::endl;
}
@ -18,14 +18,14 @@ class Animal {
class Cow : public Animal {
public:
void makeSound() {
void makeSound() const {
std::cout << "Mooh. from " << this << std::endl;
}
};
class Cat : public Animal {
public:
void makeSound() {
void makeSound() const {
std::cout << "Meow? from " << this << std::endl;
}
};

Loading…
Cancel
Save