Using Library Class Within Another Library Class (ERROR)

Hi,

I want to use a class (SonarSensor) within another class (MovementController) but when declaring the object of class SonarSensor within MovementController.h I keep getting an error:

error: expected identifier before numeric constant

SonarSensor sonar(10,11);

^

error: expected ',' or '...' before numeric constant

exit status 1
Error compiling for board ATmega128.

Could you kindly help by pointing me to what I am doing wrong?

My code is attached.

MovementController.cpp (105 Bytes)

MovementController.h (235 Bytes)

SonarSensor.h (352 Bytes)

SonarSensor.cpp (1.13 KB)

You can't initialize a variable inside of a class declaration, except for constant members. What you need to do is supply an initializer list to the MovementController and initialize your sonar in there:

class MovementController
{
private:
    SonarSensor sonar;

public:
    MovementController() : sonar(10,11)
    {
    }
};

Thank you very much, that solved it.

The initializer list concept is new to me.