Cpp reference.com在以下情况下未使用类型名,为什么?

问题描述 投票:5回答:2

我一直在阅读有关删除type, here的引用的信息>

我在链接中看到了以下代码

type

#include <iostream> // std::cout #include <type_traits> // std::is_same template<class T1, class T2> void print_is_same() { std::cout << std::is_same<T1, T2>() << '\n'; } int main() { std::cout << std::boolalpha; print_is_same<int, int>(); print_is_same<int, int &>(); print_is_same<int, int &&>(); print_is_same<int, std::remove_reference<int>::type>(); // Why not typename std::remove_reference<int>::type ? print_is_same<int, std::remove_reference<int &>::type>();// Why not typename std::remove_reference<int &>::type ? print_is_same<int, std::remove_reference<int &&>::type>();// Why not typename std::remove_reference<int &&>::type ? } 特性中的type是从属类型。

可能的实现

std::remove_reference

但是为什么它没有被使用template< class T > struct remove_reference {typedef T type;}; template< class T > struct remove_reference<T&> {typedef T type;}; template< class T > struct remove_reference<T&&> {typedef T type;};

我一直在阅读有关删除该类型的引用的信息,在这里我在链接中包含以下代码#include // std :: cout #include // std :: is_same模板<...>

c++ c++11 templates typetraits
2个回答
10
投票

typename std::remove_reference</*TYPE*/>::type特性中的type是从属类型。


0
投票

简而言之,您需要std::remove_reference<T>::type以确保编译器具有以下功能:>

T
© www.soinside.com 2019 - 2024. All rights reserved.