From: Gerhard Menzl on
Daniel Kr�gler wrote:

> This should not compile, because you are attempting to
> apply a pointer to non-const member function to references
> to const. Fix this to read:
>
> template <typename Element,
> typename Member,
> Member (Element::*memPtr)() const>
> bool lessMember(Element const& left, Element const& right)
> {
> return (left.*memPtr)() < (right.*memPtr)();
> }
>
>>
>> class C
>> {
>> public:
>> C(int i, long l) : m_i(i), m_l(l) {}
>>
>> int GetInt() { return m_i; }
>> long GetLong() { return m_l; }
>
> Given above fix, you also need to modify these member
> declarations to:
>
> int GetInt() const { return m_i; }
> long GetLong() const { return m_l; }

Sorry, the consts were in the original code I compiled, they must have
disappeared in reducing the code to the minimum. Since the error only
occurs at link time, using Comeau online to test the code is not an option.

> Please excuse that I cannot resist to smile a bit, after having
> read about the VC6 compiler in the context of templates... ;-)

I know that Visual C++ 6.0 is lousy when it comes to templates. That's
exactly why I need to sort out compiler glitches from language restrictions.

> The standard clearly says that a function must exist in this case.
> This can be deduced by the combination of [basic.def.odr]/2:
>
> "An overloaded function is used if it is selected by overload
> resolution when referred to from a potentially-evaluated expression."
>
> with [over.over]/1:
>
> "A use of an overloaded function name without arguments is resolved in
> certain contexts to a function, a pointer to function or a pointer to
> member function for a specific function from the overload set. A function
> template name is considered to name a set of overloaded functions in such
> contexts.[..]"

Thanks for pointing me to these passages, but I find them anything but
clear. Does this really apply to taking the address of the function
template specialization?


--
Gerhard Menzl

Non-spammers may respond to my email address, which is composed of my
full name, separated by a dot, followed by at, followed by "fwz",
followed by a dot, followed by "aero".


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]