From 86c0368a04f8223faef64d236f5d3895f681a86e Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 14 Apr 2014 09:10:17 +0200 Subject: [PATCH] make some methods const --- accumulate.cpp | 2 +- classes.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/accumulate.cpp b/accumulate.cpp index 95062a2..f57cc2a 100644 --- a/accumulate.cpp +++ b/accumulate.cpp @@ -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() { diff --git a/classes.cpp b/classes.cpp index 2e884fc..3da15b0 100644 --- a/classes.cpp +++ b/classes.cpp @@ -4,7 +4,7 @@ class Animal { public: // Note: using *virtual* does the difference here! - virtual void makeSound() { + virtual void makeSound() const { std::cout << " 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; } };