Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为类的特征专门化实现错误消息_C++_Templates_Template Specialization_Sfinae_Specialization - Fatal编程技术网

C++ 为类的特征专门化实现错误消息

C++ 为类的特征专门化实现错误消息,c++,templates,template-specialization,sfinae,specialization,C++,Templates,Template Specialization,Sfinae,Specialization,当库用户对模板类的模板参数使用错误类型时,如何实现错误消息 test.cpp自适应自 问题:它没有打印我想要的错误消息对不起,非整数类型t的foo尚未实现。将执行以下操作: template <typename T, typename Enable = void> class foo { static_assert(sizeof(T) == 0, "Sorry, foo<T> for non-integral type T has not been impleme

当库用户对模板类的模板参数使用错误类型时,如何实现错误消息

test.cpp自适应自

问题:它没有打印我想要的错误消息对不起,非整数类型t的foo尚未实现。

将执行以下操作:

template <typename T, typename Enable = void>
class foo
{
    static_assert(sizeof(T) == 0, "Sorry, foo<T> for non-integral type T has not been implemented");
};
您需要sizeofT==0,因为静态断言总是被计算的,并且需要依赖于T,否则它将总是被触发,即使是对于有效的T。

也会这样做:

template <typename T, typename Enable = void>
class foo
{
    static_assert(sizeof(T) == 0, "Sorry, foo<T> for non-integral type T has not been implemented");
};
您需要sizeofT==0,因为静态_断言总是被计算的,并且需要依赖于T,否则它将总是被触发,即使对于有效的T也是如此

template <typename T, typename Enable = void>
class foo
{
    static_assert(sizeof(T) == 0, "Sorry, foo<T> for non-integral type T has not been implemented");
};