Conversion functions?

I was surfing in the internet and found that class:

1
2
3
4
5
6
7
8
9
10
11
12
template <class T>
class Ptr {
private:
	T * rawptr;

public:
	struct PointerConversion { int valid; };

	operator int PointerConversion::*() const {
		return rawptr ? &PointerConversion::valid : 0;
	}
};


It's from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf

I'm confused about
1
2
operator int PointerConversion::*() const {
		return rawptr ? &PointerConversion::valid : 0; }


Why is there no return type?
What is PointerConversion::*, why is it after operator part and why along with int type?
Can we write it in some more readable way, why is it written that way?
Last edited on
Why is there no return type?
operator int means that you convert the object to an integer so the return type is implicitly int

Can we write it in some more readable way, why is it written that way?

You should be able to write it better if you knew what this class should do exactly, I don't understand the purpose at all (= bad code).

What is PointerConversion::*, why is it after operator part and why along with int type?

I'm sorry I don't know.
Thanks for replay. First one should be correct. Purpose of this class is to present a function that is able to convert class to primitive type, but this way you cannot compare Ptr<apple> == Ptr<orange>, if apple and orange are not related. That's why they didn't make just simple conversion to int, but that strange one.
EDIT:
I found what int PointerConversion::* is:
It's a member pointer to a field of type int within a PointerConversion. I'm not sure what it means, but it's easier to understand. Why is it so special, that it allows for that:
1
2
Ptr<int> p1, p2;
p1 + p2;

,but it wouldn't work with int and float?
EDIT 2:
never mind, found an answer:
https://www.google.pl/?gws_rd=ssl#q=www.experts-exchange.com%2FProgramming%2FEditors_IDEs%2FQ_20833198
Last edited on
Topic archived. No new replies allowed.