我认为C ++ 11和using
中新的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
}
当我尝试在类A的成员函数之一中使用类型vector_int
时,出现编译器错误:syntax error: identifier 'vector_int'
。
我在这里做错什么了吗?还是无法使用using
定义成员类型?