且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++模板类问题中的类型条件

更新时间:2023-11-02 08:27:22

在第二种情况下,RET是什么,取决于模板类型T.需要确保编译器在所有可能的实例化中都将是一种类型(并且可能不是IF某些实例化的静态成员).您可以使用typename关键字来实现.

In the second case, what RET is, depends on the template type T. The compiler needs to be assured that it is going to be a type in all possible instantiations (and not perhaps a static member of some instantiation of IF). You do so with the typename keyword.

template <typename T>
class Param
{
    typename IF< sizeof(int)<sizeof(long), T&, T* >::RET mParam;

};