C2236:意外标记“struct”,您是否忘记了“;” ? C2332:“结构”缺少标记名称

Sam*_*ri -2 qt templates c++11

检查过类似错误的帖子。提出的解决方案都没有帮助克服这个问题。

我已经检查了我所有的课程是否有“;” 在定义的最后......所有这些都被正确定义。

我已经检查了头文件保护的头文件。他们都有守卫

这是构建 QT 项目(桌面 GUI 应用程序)的输出。

除了上面提到的之外,这些错误的典型原因是什么?

以下是错误的输出:

include\ConfigServer.h(85):错误 C2236:意外的标记“结构”。你忘记了';'吗?

include\ConfigServer.h(85): 错误 C2332: 'struct': 缺少标签名称

这个 'ConfigServer.h' 文件包括 'BlockParam.h' 、 'CommsInfo.h' 和 'GeoInfo.h' ,我之前在一个单独的控制台项目中编译过它们以测试它们的使用。他们在控制台程序上工作。

任何见解?

#ifndef CONFIGSERVER_H
#define CONFIGSERVER_H

#include <iostream>
#include <iterator>

#include <QObject>
#include <QMap>
#include <QString>
#include <QVector>
#include <QFile>
#include <QXmlStreamReader>
#include <QDebug>

#include "BlockParam.h"
#include "CommsInfo.h"
#include "GeoInfo.h"




#define _delete(x) { if(x) delete x; x = nullptr;}

#define DEBUG 1
#define SHOW(X,B)  { if(DEBUG) { std::cout << X << B <<std::endl ; } }
#define DISPLAY(X) { if(DEBUG) { std::cout << X <<std::endl ; } }




enum ENUM_PLATFORM {
    NOTSET = 0,
    SILSIM = 1,  // Desktop Platform
    PILSIM = 2,  // PIL Platform
    HILSIM = 3   // HIL Platform
};

enum ENUM_CONFIG
{
    GEOINFO  = 1,
    COMMS    = 2, 
    MDLPARAM = 3 
};


typedef QMap<QString,ConfigInfo*> CfgMap;


class ConfigServer
{
public:

    ConfigServer();
    ~ConfigServer();

    bool LoadXmlFile(const QString xmlParmFileName);
    bool Validate(Xpci* xpc);

    bool IsValidated();
    bool errorsOccurred();
    QVector<QString> getErrorStrings();

    template<class T>
    ConfigInfo *GetConfigInfo(QString _inface,QString _pty,bool ebl);

    template<class T>
    void DisplayContent(T* Cfg) const;

    CfgMap *getMap()  const;
    QVector<CfgMap> *getConfigList()  const;

    ENUM_PLATFORM  PLATFORM;
    ENUM_CONFIG    CONFIGURATION;

    QVector<QString> ErrStringsVector;

private:

    void readModelXmlToMap(QXmlStreamReader* reader,CfgMap* ConfigMap_);

    template<class T>
    bool readCurrentInterfaceElement(QXmlStreamReader* reader,CfgMap* ConfigMap_);

    template<class T>
    bool readCurrentPropertyElement(QXmlStreamReader* reader,QString interface,CfgMap* ConfigMap_);

    bool readCurrentDimensionElement(QXmlStreamReader* reader,unsigned &rowDim,unsigned &colDim);

    BlockParam  nullBlockParam;
    CommsInfo   nullCommsInfo;
    GeoInfo     nullGeoInfo;

    CfgMap*  ConfigMap = nullptr;
    QVector<CfgMap>  *ConfigList = nullptr;

    unsigned requisite;
    bool validated = false;
    bool errorFlag = false;

};



template<> bool        ConfigServer::readCurrentInterfaceElement<BlockParam>(QXmlStreamReader* reader,CfgMap* ConfigMap_) ;
template<> bool        ConfigServer::readCurrentInterfaceElement<CommsInfo>(QXmlStreamReader* reader,CfgMap* ConfigMap_) ;
template<> bool        ConfigServer::readCurrentInterfaceElement<GeoInfo>(QXmlStreamReader* reader,CfgMap* ConfigMap_) ;

template<> bool        ConfigServer::readCurrentPropertyElement<BlockParam>(QXmlStreamReader *reader,QString interface,CfgMap* ConfigMap_);
template<> bool        ConfigServer::readCurrentPropertyElement<CommsInfo>(QXmlStreamReader *reader,QString interface,CfgMap* ConfigMap_);
template<> bool        ConfigServer::readCurrentPropertyElement<GeoInfo>(QXmlStreamReader *reader,QString interface,CfgMap* ConfigMap_);

template<> ConfigInfo *ConfigServer::GetConfigInfo<BlockParam>(QString _inface,QString _pty,bool ebl);
template<> ConfigInfo *ConfigServer::GetConfigInfo<CommsInfo>(QString _inface,QString _pty,bool ebl);
template<> ConfigInfo *ConfigServer::GetConfigInfo<GeoInfo>(QString _inface,QString _pty,bool ebl);

template<> void ConfigServer::DisplayContent<BlockParam>(BlockParam* Cfg) const;
template<> void ConfigServer::DisplayContent<CommsInfo>(CommsInfo* Cfg) const;
template<> void ConfigServer::DisplayContent<GeoInfo>(GeoInfo* Cfg) const;




#endif // CONFIGSERVER_H
Run Code Online (Sandbox Code Playgroud)

Igo*_*nik 8

在 Windows 头文件(您通过 Qt 头文件间接包含)中,有一些宏定义可以归结为#define interface struct. 你的函数声明然后被修改为

template<> bool ConfigServer::readCurrentPropertyElement<BlockParam>(
    ..., QString struct, ...);
Run Code Online (Sandbox Code Playgroud)

QString struct部分显然是胡说八道,编译器抱怨。


最简单的解决方法是避免interface用作标识符。