C++ 身份<;T>;重载函数签名中的包装器禁用重载
我有一个重载的流操作符,你想要一个与其模板参数相同的模板类型吗?为什么?没有std::identity。标识的全部意义在于防止编译器猜测T是什么,因此必须调用operator@Marc,您完全正确,失败的不是重载解析,而是类型推断。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
#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
}