Why do we write const keyword in function headers eg double
Why do we write const keyword in function headers e.g. double getWidth() const; Write the class definition (program) for a Circle that has radius attribute. Implement appropriate constructor, accessor and mutator functions for this attribute. How does inline functions affect performance?
Solution
4) To make function constant we can use const keyword in function declaration. The idea of const functions is not allow them to modify the object on which they are called.
5) code:
class Circle
{
float radius;
Circle(float r)
{
radius =r;
}
float getradius()
{
return radius;
}
float setradius(float r)
{
radius=r;
}
};
6) It reduces function call overhead. It also save overhead of variables push/pop on the stack, while function calling.
It also save overhead of return call from a function. It may increase function size so that it may not fit on the cache, causing lots of cahce miss.
