Hello
Consider the following program:
#include <iostream>
#include <string>
class TestClass
{
public:
void f(void) {}
};
template<typename T>
struct F{
typedef void (T::*Type)(void);
};
template<typename T>
void Execute_generic(T) {
std::cout << "Generic function" << std::endl;
}
template<typename T>
void Execute_generic(typename F<T>::Type) {
//void Execute_generic( void (T::*)(void) ) {
std::cout << "Specialization {void (T::*)(void)}" << std::endl;
}
template<typename T>
void Execute_generic(T*) {
std::cout << "Specialization {T*}" << std::endl;
}
template<typename T>
class C {
public:
void fun(T t) { Execute_generic(t); }
};
int main(void)
{
C<std::stringc1;
typedef void (TestClass::*pmem)(void);
C<pmemc2;
C<double*c3;
double u=0.0;
c1.fun(std::string("Hello"));
c2.fun(&TestClass::f);
c3.fun(&u);
return 0;
}
When I uncomment the line:
void Execute_generic( void (T::*)(void) )
I got output:
Generic function
Specialization {void (T::*)(void)}
Specialization {T*}
which is what I'm trying to achieve. But when I uncomment the line
that says:
void Execute_generic(typename F<T>::Type)
I got output:
Generic function
Generic function
Specialization {T*}
which I don't understand. What's the difference between void (T::*)
(void) and typename F<T>::Type.
It seems to be the same.
Compiled in Comeau online, MVisual and GCC with pedantic without
warnings.
Thanks for your help
braton