std::map

C

Christoph Rabel

Smeckler said:
Would you care to be more specific about your objection to my code?

First, this has undefined behaviour. (Dereferencing a 0 Pointer)

Second, how do you test the returned reference for 0??
You cannot. So somebody ends up with a dangling reference. And probably
crashes a while later when he tries to use it...

Christoph
 
T

tom_usenet

Kevin,

Would you care to be more specific about your objection to my code?

It has undefined behaviour. Dereferencing a null pointer is always a
bug. In other words, in the language spec, there is no such thing as a
null reference, since in order to create one, you have to go outside
the language spec.

In practice, the code will crash on some platforms, while on others it
will return what you think of as a "null reference".

Tom
 
J

jeffc

Duane Hebert said:
I prefer to use the dot operator when referencing an object that's not a
pointer. It's
a matter of taste and not worth an argument. Both ways work. To me, it
wasn't intuitive
that (*it).first would work.

The whole point is it's supposed to look like a pointer. Otherwise, you
wouldn't have to go around your elbow to get to your butt to dereference it,
thereby forcing it to look like a reference just because that's how you want
it to look.
 
J

jeffc

Duane Hebert said:
I prefer to use the dot operator when referencing an object that's not a
pointer. It's
a matter of taste and not worth an argument. Both ways work. To me, it
wasn't intuitive
that (*it).first would work.

Or to put it another way, if it were just a regular reference object, you
would access it like
it.
instead of like
(*it).
So it's not just a matter of preference in this case, it's a matte of how
the thing was designed to be used - i.e., like a pointer.
 

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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top