I am having issues setting a Spark Max to follow another Spark Max.
CANSparkMax.h is included in the .h file
'class std::shared_ptr<rev::CANSparkMax>' has no member named 'Follow'
leftFollow.Follow(leftLead)
Excerpt from code:
void Drive::Periodic() {
Put code here to be run every loop
leftFollow.Follow(leftLead);
rightFollow.Follow(rightLead);
// put elevator positions on smartdash
}
You are using a pointer, so you have to use the arrow operator to dereference the pointer and call the function, and the pointer dereference operator to dereference the argument.
leftFollow->Follow(*leftLead);
You can also manually dereference and call the function, which does exactly the same thing, but as one of my professors said, makes you look “like a novice”. You need parentheses because of operator precedence.
(*leftFollow).Follow(*leftLead);
The reason you get that error message is you are trying to call Follow on a shared_pointer, and the shared_pointer doesn’t have a Follow method.
I found a stack overflow question that may help you understand pointers in C++ better. It goes into quite a bit of detail that’s not really necessary here, but is good to know.