Subclass instanciate problems

I'm having some troubles to instanciate a subclass. The linker is giving me some errors of instanciate in my opinion. I have tried in many manners but I can't even instanciate it for using this object.


This is what linker is giving as an error:

../src/application.cpp:44:55: error: invalid conversion from 'Adafruit_MMA8451*' to 'int32_t {aka long int}' [-fpermissive]
Adafruit_MMA8451 mma = new Adafruit_MMA8451(0x12345678);
^
In file included from ../src/application.cpp:28:0:
../src/Adafruit_MMA8451.h:82:5: error: initializing argument 1 of 'Adafruit_MMA8451::Adafruit_MMA8451(int32_t)' [-fpermissive]
Adafruit_MMA8451(int32_t id );
^
make: *** [obj/src/application.o] Error 1


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
ADAFRUIT_MMA8451.H
  class Adafruit_MMA8451 : public Adafruit_Sensor {
public:
    Adafruit_MMA8451(int32_t id );


    bool begin(uint8_t addr = MMA8451_DEFAULT_ADDRESS);

    void read();

    void setRange(mma8451_range_t range);
    mma8451_range_t getRange(void);

    void setDataRate(mma8451_dataRate_t dataRate);
    mma8451_dataRate_t getDataRate(void);

    void getEvent(sensors_event_t *event);
    void getSensor(sensor_t *sensor);

    uint8_t getOrientation(void);

    int16_t x, y, z;
    float x_g, y_g, z_g;

    void writeRegister8(uint8_t reg, uint8_t value);
private:
    uint8_t readRegister8(uint8_t reg);
    int32_t _sensorID;
    int8_t _i2caddr;
};Put the code you need help with here.


1
2
3
4
5
ADAFRUIT_MMA8451.CPP

Adafruit_MMA8451::Adafruit_MMA8451(int32_t sensorID) {
    _sensorID = sensorID;
}

1
2
3
MAIN

Adafruit_MMA8451 mma = new Adafruit_MMA8451(0x12345678);
Last edited on
java is so stupid that you need to tell it twice what you want
1
2
Adafruit_MMA8451 mma(0x12345678);
Adafruit_MMA8451 mma{0x12345678}; //also valid 
Where do I have to use it??
Topic archived. No new replies allowed.