Pedantic C++ Take 3

Started by
8 comments, last by sjelkjd 18 years, 10 months ago

struct Stuff {
   int i;

   //What is this type/classification of operator called?
   operator int&() {return i;}
};
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Conversion operator. Do I get a cookie? [smile]
That's what I thought they were called, but it's a hybrid term.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
How do you mean? I have not seen them called anything else.
The standard calls them conversion functions (12.3.2 -1)

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

I've found a few instances of them informally/incorrectly being refered to as "cast operators", however a "cast operator" would be static_cast<>() and friends (and the C-style cast), as distinct from what you are refering to.
My C++ standard calls them conversion functions 12.3.2-1

I was wondering if anyone would respond cast operators because it's used so much to describe that type of operator. I've seen them called that almost everywhere. Since I was looking for conversion operator, I had trouble tracking down 'conversion function'.

Seems like conversion operator isn't too far off the mark though, but as Andrew notes cast operators really are something else!
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I call it a cast operator because it is an operator that is called when casting. Just like operator + is called when applying + on an object.
But it is also called when doing an implicit conversion =)

This topic is closed to new replies.

Advertisement