Typedef equivalence in function arguments

Posted by Warren Seine on Stack Overflow See other posts from Stack Overflow or by Warren Seine
Published on 2011-01-17T22:49:22Z Indexed on 2011/01/17 22:53 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

Hi guys,

The question is kind of hard to ask without an example so here it is:

#include <vector>

struct O
{
};

struct C
{
  template <typename T>
  void function1(void (C::*callback)(const O*));

  template <typename T>
  void function2(void (C::*callback)(const typename T::value_type));

  void print(const O*);
};


int main()
{
  C c;

  c.function1< std::vector<O*> >(&C::print); // Success.
  c.function2< std::vector<O*> >(&C::print); // Fail.
}

The error that I am given is:

error: no matching function for call to ‘C::function2(void (C::*)(const O*))’.

Basically, the only difference between calls is that in function2, I'm more generic since I use the typedef std::vector<O*>::value_type which should resolve to O*, hence similar to function1.

I'm using G++ 4.2.1 (I know it's old), but Comeau confirms I'm wrong.

Why does the compilation fail?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates