Help passing inertial sensor to class constructor

I am trying to make my own smartdrive class called smarterdrive that would take in the left and right motor groups of a robot as well as a possible inertial sensor. The problem is that when I try to set up the parameters for the constructor it comes up with the error “no default constructor exists for class “vex::inertial””. Looking at the definition for the inertial class the closest I can find is ~inertial(); but I’m not sure what the ‘~’ in front of it means and regardless it doesn’t work for my use case. Here is the code I am having the problem with, any ideas on how to fix it?

smarterdrive::smarterdrive(motor_group left, motor_group right, inertial InertialSensor){

    smarterdrive::Left = left;
    smarterdrive::Right = right;
    smarterdrive::Inertial = InertialSensor;

}

One way to do it is to pass by port and construct the inertial in the smarterdrive constructor.

3 Likes

You need to use a member initializer list when you set the values of the motors and the inertial. Basically you need to replace your linked code with this:

smarterdrive::smarterdrive(motor_group left, motor_group right, inertial InertialSensor)
    : Left(left), Right(right), Inertial(InertialSensor)
{
    // The rest of the constructor code goes here
}

The ~ (tilde) in front of it means it is a destructor, and it runs when an instance of the class is deleted.

1 Like

Sorry I didn’t include it originally but I found the error was made from me making an inertial object that wasn’t equal to nothing in the header file and for some reason it was showing up in another file entirely. Fixed it by setting it to 0 initially.

inertial SmarterInertial = 0;

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.