M
Momchil Velikov
The following program produces error at the definition of ``b''. However it
compiles fine the second (supposedly equivalent) form of the templated
constructor. Why the two alternatives aren't equivalent ?
template<class Obj>
struct ptr_to_member
{
typedef void (Obj::* type) ();
};
struct A
{
A (void (*fn) ())
{
}
#if 1
template<class Obj>
A (typename ptr_to_member <Obj>::type fn)
{
}
#else
template<class Obj>
A (void (Obj::* fn) ())
{
}
#endif
};
void foo ()
{
}
struct bar
{
void baz ()
{
}
};
A a (foo);
A b (&bar::baz);
compiles fine the second (supposedly equivalent) form of the templated
constructor. Why the two alternatives aren't equivalent ?
template<class Obj>
struct ptr_to_member
{
typedef void (Obj::* type) ();
};
struct A
{
A (void (*fn) ())
{
}
#if 1
template<class Obj>
A (typename ptr_to_member <Obj>::type fn)
{
}
#else
template<class Obj>
A (void (Obj::* fn) ())
{
}
#endif
};
void foo ()
{
}
struct bar
{
void baz ()
{
}
};
A a (foo);
A b (&bar::baz);