make some methods const
This commit is contained in:
parent
9092970b7d
commit
86c0368a04
2 changed files with 4 additions and 4 deletions
|
@ -9,7 +9,7 @@
|
||||||
int myfunction (int x, int y) { return x+2*y; }
|
int myfunction (int x, int y) { return x+2*y; }
|
||||||
|
|
||||||
struct myclass {
|
struct myclass {
|
||||||
int operator()(int x, int y) { return x+3*y; }
|
int operator()(int x, int y) const { return x+3*y; }
|
||||||
} myobject;
|
} myobject;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
class Animal {
|
class Animal {
|
||||||
public:
|
public:
|
||||||
// Note: using *virtual* does the difference here!
|
// Note: using *virtual* does the difference here!
|
||||||
virtual void makeSound() {
|
virtual void makeSound() const {
|
||||||
std::cout << "<generic animal sound> from " << this << std::endl;
|
std::cout << "<generic animal sound> from " << this << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,14 @@ class Animal {
|
||||||
|
|
||||||
class Cow : public Animal {
|
class Cow : public Animal {
|
||||||
public:
|
public:
|
||||||
void makeSound() {
|
void makeSound() const {
|
||||||
std::cout << "Mooh. from " << this << std::endl;
|
std::cout << "Mooh. from " << this << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Cat : public Animal {
|
class Cat : public Animal {
|
||||||
public:
|
public:
|
||||||
void makeSound() {
|
void makeSound() const {
|
||||||
std::cout << "Meow? from " << this << std::endl;
|
std::cout << "Meow? from " << this << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue