我不能在类中执行 typedef 吗?
#include <vector>
using namespace std;
class List {
public:
typedef int Data;
class iterator;
pair<iterator,bool> insert(const Data nodeId); //<-error
private:
class Node {
typedef vector<NodeId> DepList;//<-error
};
}
我收到错误 缺少类型说明符 - 假定为 int。注意:C++不支持default-int
最佳答案
你可以。
我猜错误就在这对线上。您是否包含了正确的 header :
#include <utility>
此外,如果您没有 using namespace std;
或 usgin std::pair;
, 你需要写 std::pair
, 而不仅仅是 pair
.
附言请不要使用 using namespace std;
,尤其是头文件。
EDIT 查看您的编辑,您需要 #include <vector>
,也是。
EDIT2:您尚未定义 NodeId
, 但您已将其用于 typedef
关于c++ - 类内的typedef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12788080/