0

In the book C++ Design Patterns and Derivatives Pricing by Mark Joshi at p.75, he writes:

const T* const operator->() const
{
    return DataPtr;
}

The first const means that it returns a const object, and the last const means that the operator is not allowed to modify the object on which it is called. But what about the second const? What is its role?

QFi
  • 281
  • 1
  • 3
  • 13
  • 1
    The second `const` is redundant. It doesn't matter whether a scalar object returned by value is `const` or not. It's an rvalue that can't be modified anyway. Further, an idiomatic smart pointer would return a plain `T*` - see e.g. [`shared_ptr::operator->`](http://en.cppreference.com/w/cpp/memory/shared_ptr/operator*) – Igor Tandetnik Nov 10 '17 at 01:14
  • Thank you, and sorry for the duplicate! – QFi Nov 10 '17 at 01:18

0 Answers0