这是我的一段代码,我有更多的类,如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/