Topic: pointer to template function ambigious to compiler


Author: smoke@casema.net
Date: 1999/11/19
Raw View
Hello,

What should happen in the code below is that in main(), the function
`void bug_function' should be created for `Argument0'.
In my opinion, doing so is the only possible option, yet most compilers
tell me that the type of argument is unknown.

Question: is this standard c++ ? g++ 2.95.2 compiles it fine.
(is the only way to find out to buy a copy of the standard?)


//-- example code begins here --

#include <iostream>

// here resides the function that cannot be templated
template <class E> class Bug {
public:
  template <class T>
  void bug_function ( void (T::*function)(E) ) {}
};

class Argument0 {};
class Argument1 {};

// this is the class where the ambigious functions reside
class Test {
public:
  void function( Argument0 ) {}
  void function( Argument1 ) {}
};

int main()
{
  Bug<Argument0> b0;

  // the following line compiles fine with g++ 2.9.2, but not with some
  // other compilers

  // egcs 2.91.60 for example says:

  // no matching function for call to
  // `Bug<Argument0>::bug_function ({unknown type})'

  b0.bug_function(&Test::function);

  return 0;
}

//-- code ends here --

thanks in advance,
--
Tijs van Bakel, <smoke@casema.net>
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: jbarfurth@vossnet.de (Joerg Barfurth)
Date: 1999/11/20
Raw View
<smoke@casema.net> wrote:

> Hello,
>
> What should happen in the code below is that in main(), the function
> `void bug_function' should be created for `Argument0'.
Make that: 'Test'                               ^^

> In my opinion, doing so is the only possible option, yet most compilers
> tell me that the type of argument is unknown.
Afaik _no_ compilers implements the standard fully yet. Member templates
and template argument deduction in complicated cases are one area where
some compilers still are deficient.

> Question: is this standard c++ ? g++ 2.95.2 compiles it fine.
> (is the only way to find out to buy a copy of the standard?)
Yes (afaics). No - you can ask in this newsgroup :-)

[snipped somewhat...]
> // here resides the function that cannot be templated
> template <class E> class Bug {
> public:
>   template <class T>
>   void bug_function ( void (T::*function)(E) ) {}
> };

> class Argument0 {};
> class Argument1 {};

> // this is the class where the ambigious functions reside
Actually 'overloaded'. Doesn't seem ambiguous to me.

> class Test {
> public:
>   void function( Argument0 ) {}
>   void function( Argument1 ) {}
> };

> int main()
> {
>   Bug<Argument0> b0;
>   // the following line compiles fine with g++ 2.9.2, but not with some
>   // other compilers

>   b0.bug_function(&Test::function);
fine, should call Bug<Argument0>::bug_function<Test>();

Looking in the Standard (14.8.2.4/p.16) Test::function(Argument0) seems
to be a unique match.

>   return 0;
> }
>
> //-- code ends here --
>
> thanks in advance,

-- J   rg Barfurth


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]