【问题标题】:Use of "using" keyword as pseudo-preprocessor [duplicate]使用“using”关键字作为伪预处理器[重复]
【发布时间】:2016-12-18 17:07:58
【问题描述】:

我最近遇到过:

using vi = vector<int>;
using mvi = map<vi, int>;

它是否等同于#define?用这个对吗?

【问题讨论】:

  • 不,它不“等同于#define”。这是正确的 C++ 语法,所以从这个意义上说,使用它是“正确的”。
  • 它实际上是typedef 的替代品,但更灵活。考虑这个更复杂的版本:template&lt;typename T&gt; using v = vector&lt;T&gt;;

标签: c++ c-preprocessor using


【解决方案1】:

此特定表单与typedef 具有相同的功能。有关using 关键字的详细说明,请参阅此帖子:What is the logic behind the "using" keyword in C++?

另外,它与#define 不同。那是一个预处理器宏。

【讨论】:

    猜你喜欢
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    相关资源
    最近更新 更多