简体   繁体   English

“错误:'.' 之前的预期不合格 ID 令牌”在 class.cpp 文件中

[英]"error: expected unqualified-id before ‘.’ token" in class.cpp file

I have some classes and variables defined as so我有一些类和变量是这样定义的

ClassA.cpp类A.cpp

//#include "ClassB.h" & "ClassA.h"

ClassA currObj;

currObj.SetInfo(...);  // works
classAVect.push_back(currObj); // "error: expected unqualified-id before ‘.’ token"

ClassA.h类A.h

//#include "ClassB.h"

private:
    typedef std::vector<ClassB> ClassAVect;

I thought that error was for accessing a class that didn't have an instance of the type.我认为该错误是因为访问没有该类型实例的类。 So I must not be accessing my private vector correctly?所以我一定没有正确访问我的私有向量? I get that error whenever I try to access that vector using ADT ( .at() , .size() , ..) in that format.每当我尝试使用该格式的 ADT( .at().size() 、..)访问该向量时,我都会收到该错误。 I thought since the vector is already of the ClassA type, then I could access it directly with push_back() .我想既然向量已经是 ClassA 类型,那么我可以直接使用push_back()访问它。 Where am I wrong?我哪里错了?

I simply removed the typedef and I was able to use the vector as normal.我只是删除了 typedef,我就可以正常使用向量了。 I don't know if I will need to change that back later on but for now, that works我不知道我是否需要稍后将其改回,但现在,这有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM