Okapi help. error: 'class std::shared_ptr<okapi::ChassisController>' has no member named 'moveDistance'

I just started using Okapi, and I am getting an error that I do not know how to fix.
The error is

src/Auttons/Blue_Other_V1.cpp:13:11: error: 'class std::shared_ptr<okapi::ChassisController>' has no member named 'moveDistance'
   13 |     drive.moveDistance(8_in);
      |           ^~~~~~~~~~~~

The full code for this part of my code is:

#include "main.h"	  // Include the PROS API 
void Blue_Other_V1(void) {
    std::shared_ptr<ChassisController> drive =
            { MleftWheelFront, -MleftWheelBack },
            { MrightWheelFront, -MrightWheelBack }
        // Green gearset, 4 inch wheel diameter, 11.5 inch wheel track
        .withDimensions(AbstractMotor::gearset::green, { {4_in, 11.5_in}, imev5GreenTPR })
        .withOdometry() // Use the same scales as the chassis (above)

Okapi.zip (14.4 MB)

How would I fix this problem? Thanks :slight_smile:

for pointers, use the → operator instead of .


I think it’s helpful to explain why the -> operator is used on pointers instead of the .operator.

The -> operator when used in the form foo->bar is actually a short cut for (*foo).bar. In this expanded form, we can see the familiar . operator, as well as one that might be unfamiliar, the * operator. The * operator is used to dereference a pointer. This means that we can use it on a pointer to get the thing that it is pointing to. In your example, drive is a pointer (technically a std::shared_ptr), so before we can access the object that it is pointing at, we must dereference it first, which means we would write something like (*drive).moveDistance(8_in);. Writing * and the parentheses is tedious, so in C and C++, the shortcut -> was added, yielding drive->moveDistance(9_in);.