1) What is the syntactic role of PointerConversion::*() in the definition of the conversion operator?
The whole declaration is of the form
operator sometype () const;
The sometype is "int PointerConversion::*". This means that the operator converts an object of the template class to a pointer to an int member of the contained PointerConversion class.
2) The author has not defined the valid data member as static and later used valid as a static member. Am I missing something here?
Yes. The expression "&PointerConversion::valid
3) How does the whole scheme work?
A Ptr<T> can be converted to a pointer to a member of Ptr<T>::PointerConversion.
I have not attempted to explain here how pointers to members work in general. If this topic is unfamiliar to you, you may wish to review a tutorial such as:
http://www.icce.rug.nl/doc
--efn
Main Topics
Browse All Topics





by: grg99Posted on 2003-12-23 at 06:47:58ID: 9991360
Oy vey, what a kludgeball way of doing things!
The conversion operator returns the address of the static variable or zero, depending on whether the pointer is nonzero or not.
I don't know all the ins-and-outs of C++ but it appears like since it's only going to be invoked on a object instance, the "valid" variable is going to exist.
Opinions will vary, but I would have used something much clearer and self-documenting, like a macro or inline function, so you'd say:
if( Okay( ThePointer ) ) { ... }