Const and Reference

Write your question here.

What does the const at the end of this function definition mean?

 
  virtual double area() const;
It means that the implicit first parameter this of the member function will have the qualifier const.
Last edited on
i.e. you cannot modify member variables (except using mutable)
And it can be invoked on constant objects of said class.
Can you only have this sort of definition with member functions or procedures?
closed account (ypfz3TCk)
The purpose of const is to modify the type of the implicit 'this' pointer. By default *this is a const pointer to a noncont version of the class type.

To answer your second question - this type of definition only arises in the contest of a class member function. *this is a pointer to a member of the object instance.
Last edited on
Brilliant!
Topic archived. No new replies allowed.