gpt4 book ai didi

C++ 错误 : expected '=' , ','、 ';'、 'asm' 或 '__attribute__'(类名)之前的 'I2Cdev'

转载 作者:行者123 更新时间:2023-11-28 06:52:42 26 4
gpt4 key购买 nike

我在尝试将 .h 文件添加到我的 CodeLite 项目时遇到此错误。这是我的文件,比较短:

#ifndef _I2CDEV_H_
#define _I2CDEV_H_

// -----------------------------------------------------------------------------
// I2C interface implementation setting
// -----------------------------------------------------------------------------
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE

// comment this out if you are using a non-optimal IDE/implementation setting
// but want the compiler to shut up about it
#define I2CDEV_IMPLEMENTATION_WARNINGS

// -----------------------------------------------------------------------------
// I2C interface implementation options
// -----------------------------------------------------------------------------
#define I2CDEV_ARDUINO_WIRE 1 // Wire object from Arduino

// -----------------------------------------------------------------------------
// Arduino-style "Serial.print" debug constant (uncomment to enable)
// -----------------------------------------------------------------------------
//#define I2CDEV_SERIAL_DEBUG

//#include "Arduino.h"
//#include <Wire.h>
///
// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
#define I2CDEV_DEFAULT_READ_TIMEOUT 1000

**class I2Cdev {** //this line has the error
public:
I2Cdev();

static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
//static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
//static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
//static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
//static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);

static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
//static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
//static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);

static uint16_t readTimeout;
};

#endif /* _I2CDEV_H_ */

为什么我会收到此 cpp 错误以及如何修复?

编辑

我有另一个包含结构的头文件,它的格式可能不正确?在这里:

#ifndef _CALLIB_H_
#define _CALLIB_H_

//#include <Arduino.h>

#define CALLIB_DATA_VALID 0x15fc
#define CALLIB_DATA_VALID_LOW 0xfc // pattern to detect valid config - low byte
#define CALLIB_DATA_VALID_HIGH 0x15 // pattern to detect valid config - high byte

typedef struct
{
short valid; // should contain the valid pattern if a good config
bool magValid; // true if mag data valid
short magMinX; // mag min x value
short magMaxX; // mag max x value
short magMinY; // mag min y value
short magMaxY; // mag max y value
short magMinZ; // mag min z value
short magMaxZ; // mag max z value
bool accelValid; // true if accel data valid
short accelMinX; // mag min x value
short accelMaxX; // mag max x value
short accelMinY; // mag min y value
short accelMaxY; // mag max y value
short accelMinZ; // mag min z value
short accelMaxZ; // mag max z value
} CALLIB_DATA;

// calLibErase() erases any current data in the EEPROM

void calLibErase();

// calLibWrite() writes new data to the EEPROM

void calLibWrite(CALLIB_DATA * calData);

// calLibRead() reads existing data and returns true if valid else false in not.

bool calLibRead(CALLIB_DATA * calData);

#endif // _CALLIB_H_

最佳答案

您在此之前包含的头文件在最终类型定义中缺少一个分号:

struct S {
} s /* right here */

或许

typedef struct
{
} S /* right here */

中间的一切只是预处理器命令,不影响编译器解析状态。

错误消息中“预期”的内容是可以跟在 typedef 中命名的标识符或变量声明中命名的标识符之后的所有内容。

关于C++ 错误 : expected '=' , ','、 ';'、 'asm' 或 '__attribute__'(类名)之前的 'I2Cdev',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23617088/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com