【问题标题】:What are the rules to typedef and pointers in c++? [duplicate]c++中typedef和指针的规则是什么? [复制]
【发布时间】:2012-01-31 19:28:31
【问题描述】:

可能重复:
C++ typedef interpretation of const pointers

我刚刚了解到typedef 用指针做了一些奇怪的事情

这是一个例子:

typedef float* fptr;
const fptr f; // This is float * const f instead of const float * (like I wanted)

为什么要这样做?

【问题讨论】:

  • 这怎么“奇怪”?它完全按照锡上所说的那样做。 C++ 确实包含“奇怪的东西”,但这当然不是一个例子。
  • 阅读您所写的内容。 fptr 是什么?它是一个指向浮动的指针。当你保持不变时,你会得到什么?一个指向浮点数的常量指针。

标签: c++ pointers typedef


【解决方案1】:

好像已经回答了:

C++ typedef interpretation of const pointers

有关 typedef 和指针的更多讨论,另请参阅 Is it a good idea to typedef pointers?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-21
    • 2013-06-27
    • 2016-09-25
    • 2010-09-14
    • 2011-11-29
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多