Difference between virtual void funcFoo() const = 0 and virtual void funcFoo() = 0;
The first signature means the method can be called on a const instance of a derived type. The second version cannot be called on const instances. They are different signatures, so by implementing the second, you are not implementing or overriding the first version.
struct Base {
virtual void foo() const = 0;
};
struct Derived : Base {
void foo() { ... } // does NOT implement the base class' foo() method.
};
virtual void funcFoo() const = 0;
// You can't change the state of the object.
// You can call this function via const objects.
// You can only call another const member functions on this object.
virtual void funcFoo() = 0;
// You can change the state of the object.
// You can't call this function via const objects.
The best tutorial or FAQ I've seen about const correctness was the C++ FAQ by parashift:
http://www.parashift.com/c++-faq-lite/const-correctness.html
The difference is that the first function can be called on const
objects, while the second can't. Moreover, the first function can only call other const
member functions on the same object. Regarding inheritance, they behave the same way.
See also the C++ FAQ on this topic.