65,210
社区成员
发帖
与我相关
我的任务
分享//通用Type1, Type2
template<class T1> struct type_traits
{
template<class T1, class T2> struct Foo
{
Foo(T1 t1, T2 t2)
{
std::cout << "noint+type1" << std::endl;
}
};
};
//特化的int,Type2
// template<> struct type_traits<int>
// {
// template<class Type1, class Type2> struct Foo
// {
// Foo(Type1 t1, Type2 t2)
// {
// std::cout << "int+type2" << std::endl;
// }
// };
// };
//
//Wrapper 类
template<class T1, class T2>
struct FooWapper : public type_traits<T1>::Foo<T1, T2>
{
FooWapper(T1 t1, T2 t2) : type_traits<T1>::Foo<T1, T2>(t1, t2) {}
};
//maker函数用于推演
template<class T1, class T2>
FooWapper<T1, T2> inline make_foo(T1 t1, T2 t2)
{
return FooWapper<T1, T2>(t1, t2);
}
//测试程序
void main()
{
// make_foo(1, 2.0); //调用特化的<int, type2>
// make_foo("a", 2.0); //调用通用的<type1, type2>
}//Wrapper 类
template<class T1, class T2>
struct FooWapper : public type_traits<T2>::Foo<T1, T2>
{
FooWapper(T1 t1, T2 t2) : type_traits<T2>::Foo<T1, T2>(t1, t2) {}
};
#include<iostream>
using namespace std;
//通用Type1, Type2
template<class T1> struct type_traits
{
template<class T3, class T2> struct Foo
{
Foo(T1 t3, T2 t2)
{
std::cout << "noint+type1" << std::endl;
}
};
};
//特化的int,Type2
// template<> struct type_traits<int>
// {
// template<class Type1, class Type2> struct Foo
// {
// Foo(Type1 t1, Type2 t2)
// {
// std::cout << "int+type2" << std::endl;
// }
// };
// };
//
//Wrapper 类
template<class T1, class T2>
struct FooWapper : public type_traits<T2>::Foo<T1, T2>
{
FooWapper(T1 t1, T2 t2) : type_traits<T2>::Foo<T1, T2>(t1, t2) {}
};
//maker函数用于推演
template<class T1, class T2>
FooWapper<T1, T2> inline make_foo(T1 t1, T2 t2)
{
return FooWapper<T1, T2>(t1, t2);
}
//测试程序
int main()
{
// make_foo(1, 2.0); //调用特化的<int, type2>
// make_foo("a", 2.0); //调用通用的<type1, type2>
return EXIT_SUCCESS;
}
上述代码在mingw下通过!!
//通用Type1, Type2
template<class T1> struct type_traits
{
template<class T3, class T2> struct Foo
{
Foo(T1 t3, T2 t2)
{
std::cout << "noint+type1" << std::endl;
}
};
};