c++ - 类内的typedef

标签 c++ typedef

我不能在类中执行 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/

相关文章:

c++ - 当到达 main() 时,由全局变量的构造函数初始化的静态模板变量为空

c++ - Hook kernel32.dll 函数使我的程序无法运行

c++ - typedef 和 using 有什么区别?

c++ - 如何从 C++ 源代码中提取所有类型定义、结构和 union

Typedef 中的 C++ 指针

c++ - 在集合中使用嵌套类时出现类型不完整错误

c++ - 有没有办法从 Xcode 调试器的调用堆栈中删除内联函数?

android - OpenCV undefined reference

c - typedef有什么用?

c++ - "using"创建类型别名的论点是否已经确定?