I'm quite new to C++ and it might be a problem with me not knowing how to do things properly but I want my class _MPU6050
to have two functions that return a struct
. I tried several forms of declaring the struct
to no avail, I always get this error:
MPU6050.cpp:43: error: no 'int _MPU6050::SensorDataRaw::getRawGyroValues()' member function declared in class '_MPU6050::SensorDataRaw'
ISO C++ forbids declaration of 'getRawAccValues' with no type [-fpermissive]
As I understand, the compiler doesn't recognize the function _MPU6050::SensorDataRaw::getRawGyroValues()
and tries to add the return type int
at the beginning.
Here is my code:
MPU6050.cpp:
#include "MPU6050.h"
...
_MPU6050::SensorDataRaw MPU6050::getRawAccValues(){
Wire2.beginTransmission(ADD);
Wire2.write(GET_ALL_ACC);
Wire2.endTransmission();
Wire2.requestFrom(ADD, 6);
sensorData.ax = Wire2.read()<<8 | Wire2.read();
sensorData.ay = Wire2.read()<<8 | Wire2.read();
sensorData.az = Wire2.read()<<8 | Wire2.read();
return sensorData;
}
_MPU6050::SensorDataRaw MPU6050::getRawGyroValues(){
Wire2.beginTransmission(ADD);
Wire2.write(0x43);
Wire2.endTransmission();
Wire2.requestFrom(ADD, 6);
sensorData.gx = Wire2.read()<<8 | Wire2.read();
sensorData.gy = Wire2.read()<<8 | Wire2.read();
sensorData.gz = Wire2.read()<<8 | Wire2.read();
return sensorData;
}
MPU6050.h:
class _MPU6050
{
public:
struct SensorDataRaw{
int16_t ax, ay, az, gx, gy, gz;
};
public:
_MPU6050(void);
void setXGyroOffset(int16_t offset);
void setYGyroOffset(int16_t offset);
void setZGyroOffset(int16_t offset);
void setXAccOffset(int16_t offset);
void setYAccOffset(int16_t offset);
void setZAccOffset(int16_t offset);
SensorDataRaw getRawAccValues();
SensorDataRaw getRawGyroValues();
private:
SensorDataRaw sensorData;
};
Please let me know what I'm doing wrong. Thank you!