【问题标题】:Syntax error while defining class in C++在 C++ 中定义类时出现语法错误
【发布时间】:2014-01-27 00:29:44
【问题描述】:

我试图在 C++ 中创建这个类,但编译器在它的声明中不断给我一个语法错误。全局变量是必需的。

这是错误信息

include\SInterface.h(36):错误 C2061:语法错误:标识符 'SInterfaceClass'

#ifndef __SINTHDR__
#define __SINTHDR__
#include "Global.h"

typedef unsigned int  uint;

typedef struct
{
    float d1;
    float d2;
    float d3;
    float d4;
    float para;
    float mode;
} DeflStruct;

// Simulation Inputs
// ====================================================================
    float SimAcc [3] = {0};
    float SimGyr [3] = {0};
    //
    // More Global floats being defined here
    //
    float SimOutPara    =  0 ;
    float SimOutMode    =  0 ;

class SInterfaceClass {  // line 36
private:
    float ITime;
    float IPrevTime;
    //
    // More floats being defined here
    //
    float Ic1_bf_psi_rate;
    float Ic1_bf_phi_rate;


public:
    SInterfaceClass();
    DeflStruct Output(
                    Vect3   Acc ,
                    Vect3   Gyr ,
                    double  Pre ,
                    Vect3   Vel ,
                    Vect3   Eul ,
                    Vect3   Inc ,
                    Vect3   Pos ,
                    double  Time);

};

#endif 

【问题讨论】:

  • 您为什么使用typedef struct 而不仅仅是struct
  • 有什么重要的 int Global.h
  • 这个类是接口的一部分,应该将纯 C 语言编写的程序连接到 Simulink/Matlab 仿真模型。就在这之前,我正在研究它,并且是自动完成的。
  • 等等,你是用 C 还是 C++ 编译? C 没有类。
  • 发布一个重现此错误的 complete sn-p。正如所写的,不包括Global.h 愉快地通过标记线而没有错误并继续直到Vect3 成员,其中当然无效,因为没有Global.h

标签: c++ class syntax-error declaration


【解决方案1】:

我看到两个原因。第一个错误是由于标头 "Global.h"

中的一些不一致导致的

第二个是编译器将您的代码编译为 C 代码而不是 C++ 代码。

【讨论】:

  • Global.h 据我所知很好。我已经编译并测试了它,并且我已经检查了它是否使用 #ifdef __cplusplus 编译 C++
猜你喜欢
  • 1970-01-01
  • 2016-07-23
  • 1970-01-01
  • 1970-01-01
  • 2019-07-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多