这段代码可以用VS (/za)编译,但不能用GCC编译。谁是对的,谁是错的?或者两者都是错的/对的?
#include <iostream>
#include <type_traits>
using namespace std;
struct NullType
{
//NullType(){}
template<class T>
NullType(T value){}
enum {value};
};
template<class T>
struct IntType
{
typedef T type;
};
template<int value_>
struct Low
{
typedef int type;
enum {value = value_};
};
template< class T>
struct Low_impl
{
protected:
T value_;
Low_impl():value_(T()){/*e.b.*/}
Low_impl(T value):value_(value){/*e.b.*/}
};
template<class T>
struct isNullType
{
enum {value = false};
};
template<>
struct isNullType<NullType>
{
enum {value = true};
};
template<class T>
struct TypeTraits
{
typedef T type;
};
/*template<>
struct TypeTraits<int>
{
typedef int type;
};*/
template<class Int_>
struct Int_Type_Tag
{
static_assert(std::is_integral<Int_>::type,"Non Integral Type Is ILLEGAL As a Parameter to this class ");
typedef Int_ type;
};
template<class T>
struct TypeTraits<Int_Type_Tag<T>>
{
typedef typename Int_Type_Tag<T>::type type;
};
template<class Int_Type,class L = NullType>
struct Int : private std::conditional<isNullType<L>::value,
NullType,
Low_impl<typename TypeTraits<Int_Type>::type>>::type
{
typedef typename std::conditional<isNullType<L>::value,
NullType,
Low_impl<typename TypeTraits<Int_Type>::type>>::type BaseType;
Int():BaseType(L::value){}
};
int main()
{
Int<int> a;
cout << sizeof(a);
return 0;
} 来自GCC 4.5.1的错误
错误:对‘NullType::NullType(NullType::&)’的调用没有匹配的函数
发布于 2011-03-14 01:48:05
您需要使用匿名枚举NullType::value的类型实例化NullType::NullType(T)。
这是在gcc 4.5中实现的N2657所允许的。
https://stackoverflow.com/questions/5290770
复制相似问题