c++ - 这个c++ typedef有什么问题?

标签 c++ inheritance vector typedef

这是我的一段代码,我有更多的类,如MathStudent、ArtStudent等继承了Student类。当我尝试编译时,它说“禁止声明没有类型的‘vector’”,这是什么问题? 谢谢

class Student {
public:
    typedef vector<Student> Friends; // something wrong here?

    virtual unsigned int getId() = 0;

    //some more pure virtual functions...
};

最佳答案

您不能使用尚未定义的类。但是,您可以使用指向该类的指针。

您现在的具体错误可能是您忘记了 #include <vector>或者做 using namespace std; .但是一旦你解决了这个问题,你就会需要我的第一个建议。

关于c++ - 这个c++ typedef有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1698838/

相关文章:

c++ - directx C++ 第一人称相机

c++ - 自定义成员检测器中的模糊调用

c++ - 检测 CRTP 基类的 sibling

javascript - 创建孪生对象 a.k.a. 继承克隆

c++ - runtime_error 期待 ";"?

java - 通过 vector 相加

c++ - 按 x 值排序坐标

c++ - 游戏编程库C++

c++ - STL 排序对字符串 vector 与字符串指针 vector 的性能比较

c++ - 在 C++ 中对 Vector 进行并行化操作的最快方法?