首页 > 解决方案 > 在课堂上使用 vs typedef

问题描述

我认为usingC++11 中的新语法typedef是等效的(模板除外)。但似乎using也无法声明类成员。

class A {
   //... Public members 
private:
    typedef std::vector<double> vector_double; 
    using vector_int = std::vector<int>;        

    void bar(vector_double& vecDouble); // type can be used
    void foo(vector_int& vecInt); // type can't be used: synatx error
 // ... Possible other private members
}

当我尝试vector_int在 AI 类的成员函数之一中使用类型时,会出现编译器错误:syntax error: identifier 'vector_int'.

我在这里做错了什么还是定义了一个不可能的成员类型using

标签: c++c++11typedefusingusing-declaration

解决方案


推荐阅读