proper form for const version of operator->

T

t

What should the correct form of the const version of operator-> ?

Lippman does something like:

const Item_base* operator->() const

I have another book (Mark Joshi's C++ Design Patterns and Derivatives
Pricing) that adds a 3rd const keyword, so he would write the line of
code above as:

const Item_base* const operator->() const
 
V

Victor Bazarov

t said:
What should the correct form of the const version of operator-> ?

Lippman does something like:

const Item_base* operator->() const

I have another book (Mark Joshi's C++ Design Patterns and Derivatives
Pricing) that adds a 3rd const keyword, so he would write the line of
code above as:

const Item_base* const operator->() const

The top-level const (the one making Mark Joshi's variation different
from Lippman's) is irrelevant. The function returns an r-value of
"a pointer to a const Item_base". Such r-value is immutable anyway
(there is no mechanism that would provide a way to change it) hence
declaring it 'const' is meaningless.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top