【问题标题】:typename gives strange result - in codeblockstypename 给出了奇怪的结果 - 在代码块中
【发布时间】:2011-12-08 09:53:01
【问题描述】:

这段代码来自main:

Int<> a;
    cout << typeid(Int<>::range_type).name();  

使用 gcc 4.6.1 在代码块中编译时给出输出“x”。有什么理由吗?

template<class Int_T>
struct Best_Fit
{//evaluate it lazily ;)
    typedef typename if_<std::is_signed<Int_T>::value,Signed_Type,Unsigned_Type>::type type;
};

template<class Int_T = int, typename Best_Fit<Int_T>::type Min_Range = std::numeric_limits<Int_T>::min(), typename Best_Fit<Int_T>::type Max_Range = std::numeric_limits<Int_T>::max()>
class Int {
    public:
    typedef decltype(Min_Range) range_type;
};

【问题讨论】:

  • 我添加了 C++11,因为你使用了 C++11 的特性(constexprdecltype)。

标签: c++ gcc c++11


【解决方案1】:

typename Best_Fit&lt;Int_T&gt;::type 在您执行的实例化中将产生Signed_Type。由于您没有显示它的定义,我们不知道它是什么类型。但是c++filt -t x 说它是long long

回想一下,typeid(...).name() 可以生成它想要的任何名称。 GNU libstdc++ 会产生错位的类型名称。

【讨论】:

  • @litb 我在哪里可以学习如何使用 c++filt?尝试谷歌,但没有多大成功。
猜你喜欢
  • 2017-02-02
  • 1970-01-01
  • 2019-07-31
  • 1970-01-01
  • 1970-01-01
  • 2013-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多