我正在使用SFINAE机制,以推断出一种类型。 <>代码>Resolve<T>: 类型 缩略语
class MyClass {};
template<typename>
struct void_ { typedef void check; };
template<typename T, typename = void>
struct Resolve { typedef T type; };
template<typename T>
struct Resolve <T, typename void_<typename T::yes>::check> {
typedef MyClass type;
};
现在,我有一个简单的测试班,即:
struct B1 { typedef int yes; }; // 1
struct B2 { typedef int yes; }; // 2
struct D1 {}; // 3
struct D2 : B1 {}; // 4
struct D3 : B1, B2 {}; // 5 <----
根据以下逻辑,上述测试的结果应是:
Resove<B1>::type = MyClass
Resove<B2>::type = MyClass
Resove<D1>::type = D1
Resove<D2>::type = MyClass
Resove<D3>::type = MyClass
or compiler error (due to ambiguity between B1, B2)
Strangely, in test case (5) it doesn t happen so. The result is,
Resolve<D3>::type = D3;
谁可以解释,什么是