Question on Myers #30

M

Marcelo Pinto

White Wolf said:
No, they don't.

I have a copy of C++ Coding Standards by Sutter and Alexandrescu and
Scott Meyers is cited in 50 of the 100 items. And I once read one of
the Exceptional books and it said something like "Effective CD is a
good source of information"
 
H

Howard

Jonathan Turkanis said:
Were talking about "Avoid member functions that return pointers or
references to
members
less accessible than themselves," right?

Not exactly. The reason I jumped in was that Mr. Meyers' whole point
revolved around the reference being non-const. He was just showing one way
that data that should be private can be exposed via a public interface, and
that such a thing be avoided by using a const reference instead.

This is the same as my example, and I'm arguing that contrary to Meyers,
sometimes it's okay. I've given the argument twice now.

I will certainly concede that sometimes it is appropriate, and maybe even
needed. Mr. Meyers' statement was to "avoid" such a thing, which in my
opinion leaves plenty of room for "sometimes". :) And I still feel he's
got a valid point, certainly not rubbish, even if it wouldn't make a good
"hard and fast rule". Something to at least consider when designing a class
with private data, certainly. But really, my whole point in being here was
to correct the OP's posting that left off the critical "non-const" part, not
to argue the validity or scope of Mr. Meyers' argument.

-Howard
 
M

Master of C++

Oops ! I just nocited that my library (still !) has the first edition
of Meyer's book. In the first edition, he did not have that "non-const"
modifier in his chapter, but he seems to have corrected it in the
second edition. Even then, I wish he mentioned somewhere that it is ok
to do it in certain situations (esp, containers).

-Vijay.
 
J

Jonathan Turkanis

Howard said:
Not exactly. The reason I jumped in was that Mr. Meyers' whole point
revolved around the reference being non-const.

But I was talking about non-const references.
He was just showing
one way that data that should be private can be exposed via a public
interface, and that such a thing be avoided by using a const
reference instead.



I will certainly concede that sometimes it is appropriate, and maybe
even needed. Mr. Meyers' statement was to "avoid" such a thing,
which in my opinion leaves plenty of room for "sometimes". :)

True, except that in the desicussion following the heading he says that
violating the rule (or guidline, or rule of thumb, or whatever) doesn't make
sense.

He also says that returning a non-const reference to member data is equivalent
to making it public, which is another thing I was arguing against.

Jonathan
 
J

Jonathan Turkanis

Ioannis said:
std::pair, for example the one returned from map, contains copies of
the elements.

This relates to the design of std::map, not std::pair. There's good reason not
to be able to freely modify key in map.

Jonathan
 
I

Ioannis Vranos

Jonathan said:
This relates to the design of std::map, not std::pair. There's good reason not
to be able to freely modify key in map.


Yes. Perhaps I did not understand your point.
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top