I’ve been using c++ with vex v5 for a few years now, but I wanted to switch to PROS so I could use Path.JerryIO and other tools. I’m trying to configure everything but this is throwing an error for some reason. I am not using tracking wheels, and I tried using nullptr for those but it threw the same error. Why?
Let’s look at the Lemlib API reference:
So, we can see that trying to call this constructor with a single parameter isn’t going to work at all. So, we add
nullptr
where we don’t have a sensor:
lemlib::OdomSensors sensors(nullptr, nullptr, nullptr, nullptr, imu);
But we still get the error: “no instance of constructor “lemlib::OdomSensors::OdomSensors” matches the argument list” Why!?
Let’s take a closer look at the signature for the OdomSensors constructor:
OdomSensors(TrackingWheel* vertical1, TrackingWheel* vertical2, TrackingWheel* horizontal1,
TrackingWheel* horizontal2, pros::Imu* imu);
If we look closelier, we’ll see that this is the parameter for specifying an IMU:
pros::Imu* imu
What does the *
mean? In this context, it means that we are meant not to pass a pros::Imu
object, but a pointer to a pros::Imu
object. In short, a pointer is the address of the location of the pros::Imu
object which lemlib will use to be able to access the object directly. Without this, we would have to pass a copy of our whole imu
object which could cause a number of issues.
So, how do you get a pointer to our object imu
? We use the &
operator to get a reference to the imu
, which is the value of the address of the imu
object. For example:
lemlib::OdomSensors sensors(nullptr, nullptr, nullptr, nullptr, &imu);
And this time, we find that the linter is satisfied and our project builds correctly!
If you want to learn more about pointers, which are a very foundational and useful concept in many programming languages, I highly recommend reading this article/tutorial about them: 12.7 — Introduction to pointers – Learn C++