5,530
社区成员
发帖
与我相关
我的任务
分享
template<class S, class T>
struct SameClass
{
template<class Identical, Identical> //A: 这个一般都是 typename A, typename B吧。。这样写有啥特殊语法么?
struct type_match;
template<class _1>
static char (& func(
type_match< T& (_1::*)(const _1&), &_1::operator => *) )[1]; // 这个必须用这种写法才能有效果,请问下这种写法的含义是啥。。跟之前(A:)的有啥匹配关系?
template<class >
static char (& func(...))[2];
static bool const value = sizeof(func<S>(0)) == 1;
};
template<class c1, class c2>
bool IsSameClassAs() { return SameClass<c1,c2>::value == 1; }
template<class>
struct A
{
};
int main()
{
A<int> a;
}
struct B {};
struct A
{
B& operator=( const A& );
};
int main()
{
printf( "%d\n" , IsSameClassAs<A,B>() );// 1
printf( "%d\n" , IsSameClassAs<A,A>() );// 0
}
struct C1
{
};
struct C2
{
C1 &operator = (C2 const &);
};
struct C1
{
};
struct C2
{
C1 &operator = (C2 const &);
};