Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码如下
#include <vector> using namespace std; ... class A { NEW_TYPE a; ... public: typedef vector<int> NEW_TYPE; ... }
错误说'NEW_TYPE'没有命名类型
有谁知道是什么问题?
谢谢
通常,C++ 中的名称只有在声明后才能使用:
typedef int foo; foo x = 1; // OK bar y = 2; // Error typedef int bar; // too late
你的课也是如此。向上移动 typedef:
class A { public: typedef std::vector<int> NEW_TYPE; private: NEW_TYPE a; // ... public: // ... };