473,414 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

proper form for const version of operator->

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

Oct 4 '07 #1
1 1245
t wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nick Savoiu | last post by:
In the code below how can I get x to use the const T& operator? Thanks, Nick #include <stdio.h> template <typename T> class C { public:
6
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
6
by: nin234ATIyahoo.com | last post by:
Hi all I have a logger class and facing the following issue enum eErrLvl { eLOG_DEBUG_5 = 1, eLOG_DEBUG_4, eLOG_DEBUG_3, eLOG_DEBUG_2, eLOG_DEBUG_1,
2
by: Mark Stijnman | last post by:
I would like to be able to have an object accessible as a vector using the operator, but able to track modifications to its data, so that it can update other internal data as needed. I figured...
2
by: Claudius | last post by:
Hello, I have written a class A with the access operator(int) overloaded by a A-const version which returns an int by value: ------------------------------------------------ #include...
19
by: scroopy | last post by:
Is it impossible in C++ to create an assignment operator for classes with const data? I want to do something like this class MyClass { const int m_iValue; public: MyClass(int...
0
by: wellingj | last post by:
A little back ground on what I'm trying to do: I'm making a generic weighted graph class (vertexes and edges althought I don't call them that) to implement some pathfinding algorithms like A* and D*....
6
by: 2beagles | last post by:
So, I have not written c++ in quite a while and am trying to dig back in to it. I am running in to a weird situation and I am hoping someone might be able to explain it. I have a class...
10
by: Erik Knudsen | last post by:
Hi! In converting applications from ansi to unicode, it is a problem that the std::wcout accepts a const char * without complaining compile time. This compiles and runs:...
19
by: fungus | last post by:
I define this class: class foo { std::vector<int>data; public: int operator(int n) { return data; }
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.