[英]“does not name a type” error when referencing a typedef from a class
I have the following definition of a typedef in a class 我在类中定义了typedef
/*
*ReportData.h
*/
class ReportData {
public:
/** Classifiers information **/
typedef struct{
char *classifier;
uint8_t numCategories;
char **categories;
int *ranges;
} Classification;
};
This code is later referenced as follows 该代码稍后引用如下
/*
* DynamicCarDetection.cpp
*/
#include <DataReport.h>
int numOfClassGroups = 1;
int numOfCategories = 2;
ReportData::Classification *vehiclesClassificators;
vehiclesClassificators = new ReportData::Classification[numOfClassGroups];
vehiclesClassificators[i].numCategories = NumOfcategories;
vehiclesClassificators[i].categories = new char *[numOfcategories];
When I try to compile with this command 当我尝试使用此命令进行编译时
g++ -c DynamicCarDetection.cpp -I ./
I get this error on each reference to vehiclesClassificators 我对每个对vehClassificators的引用都会出现此错误
DynamicCarDetection.cpp:12:1: error: 'vehiclesClassificators' does not name a type
DynamicCarDetection.cpp:12:1:错误:'vehiclesClassificators'没有命名类型
Looks like an obvious error of name scoping, but I've struggling to understand what the problem is, because apparently, the typedef ReportData::Classification is being recognized. 看起来像名称范围的明显错误,但我很难理解问题是什么,因为显然,typedef ReportData :: Classification正在被识别。
Many thanks in advance 提前谢谢了
In C++, sentences (except some corner cases) must be part of a function body. 在C ++中,句子(除了一些极端情况)必须是函数体的一部分。 And in your CPP file there are none, so the compiler gets confused about what you are doing.
在您的CPP文件中没有,所以编译器对您正在做的事情感到困惑。
#include <DataReport.h>
void DoThings()
{
int numOfClassGroups = 1;
//....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.