Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/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++ 身份<;T>;重载函数签名中的包装器禁用重载_C++_Templates_Function Template - Fatal编程技术网

C++ 身份<;T>;重载函数签名中的包装器禁用重载

C++ 身份<;T>;重载函数签名中的包装器禁用重载,c++,templates,function-template,C++,Templates,Function Template,我有一个重载的流操作符,你想要一个与其模板参数相同的模板类型吗?为什么?没有std::identity。标识的全部意义在于防止编译器猜测T是什么,因此必须调用operator@Marc,您完全正确,失败的不是重载解析,而是类型推断。 #include <iostream> template <typename T> struct ebenso // because I could not find std::identity, any hint? { t

我有一个重载的流操作符,你想要一个与其模板参数相同的模板类型吗?为什么?没有std::identity。标识的全部意义在于防止编译器猜测T是什么,因此必须调用operator@Marc,您完全正确,失败的不是重载解析,而是类型推断。
#include <iostream>

template <typename T>
struct ebenso // because I could not find std::identity, any hint?
{
        typedef T type;
};

template <typename T>
struct X
{
        T value;
};

template<typename T>
inline std::ostream  & 
operator << (std::ostream& stream, typename ebenso< X<T> >::type const & x)
{
        return stream << x.value << std::endl;
}

int main ()
{
        X<int> x;
        x.value = 7;
        std::cout << x << std::endl; // The overload is not found
}