相关疑难解决方法(0)

如何从模板类中的方法返回NULL

我有一个看起来像这样的方法:

template <typename T>
T Test<T>::FindItem(T item)
{
    if(found)
        //return original value, no problem here
    else
        //I want to return NULL here, like:
        return NULL; 
}
Run Code Online (Sandbox Code Playgroud)

这在某些情况下在运行时失败,因为某些值在C++中无法转换为NULL,例如,std::string.我应该遵循什么方法?

c++ templates

5
推荐指数
4
解决办法
9060
查看次数

标签 统计

c++ ×1

templates ×1