Pedantic C++ Take 3

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

struct Stuff {
int i;

//What is this type/classification of operator called?
operator int&() {return i;}
};


Share on other sites
Conversion operator. Do I get a cookie? [smile]

Share on other sites
That's what I thought they were called, but it's a hybrid term.

Share on other sites
How do you mean? I have not seen them called anything else.

Share on other sites
The standard calls them conversion functions (12.3.2 -1)

Share on other sites
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.

Share on other sites
My C++ standard calls them conversion functions 12.3.2-1

Share on other sites
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!

Share on other sites
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.

Share on other sites
But it is also called when doing an implicit conversion =)

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 20
• 12
• 13
• 14
• 80
• Forum Statistics

• Total Topics
632144
• Total Posts
3004400

×