Reputation: 833
Taking for example this method declaration:
const Vector Vector::operator - ( const Vector& other ) const;
I know that the second const makes the Vector passed as an argument immutable, and that the last const declares that the method does not change the current instance of the Vector class....
const
mean or lead to?Upvotes: 6
Views: 1536
Reputation: 643
The first const means that this operator will return a constant Vector object.
Upvotes: 4
Reputation: 263360
It is an outdated security measure to prevent nonsense code like a - b = c
to compile.
(I say "outdated" because it prevents move semantics which only works with non-const rvalues.)
Upvotes: 9
Reputation: 1427
It means the return value is a const Vector
.
It has more meaning in cases such as this: const int& Vector::get(int index) const;
Upvotes: 0