Issues with a header file


Don’t laugh at me for this, I’m having issues with my robot class.

I’m declaring a robot class in a custom header file and then including it in my main file. For some reason I can’t get the functions to work in the main file.

This is my first time attempting this so I know it’s a stupid mistake but I have no clue what to do!

Attached are the .cpp and .h files!


NOTE: Its an alteration of the original Iterative default code sample posted on this site earlier, my thanks to whoever did that!

MyRobot.cpp (1.8 KB)
RobotClass.h (572 Bytes)

MyRobot.cpp (1.8 KB)
RobotClass.h (572 Bytes)

One issue immediately jumps out to me. You’re declaring your Victors, Relay and Joystick as objects in the header file, but initializing them in the constructor as if they were pointers. You need to either declare them as pointers (e.g. Victor* leftDrive) or fix your constructor to have an initialization list:

IterativeDefaultRobot::IterativeDefaultRobot(void) :
leftDrive(1), rightDrive(2), driveStick(1), testspike(1)

If you’re having problems apart from that, it would be great if you could post the relevant compiler output.

A couple of things I noticed:

– Try including the RobotClass.h header in MyRobot.cpp. The compiler often times needs the type definition to work off of. It can’t hurt in any case.
– Your class is called IterativeDefaultRobot in MyRobot.cpp, but IterativeRobotDefault in RobotClass.h (make sure to change your constructor name as well)
– testspike has a lowercase s in MyRobot.cpp and an uppercase S in RobotClass.h
– The issue that Pat pointed out is true, but also you’re using a dereferencing operator (->) on an object instead of a member access operator (.). Looks like you actually want to declare them as pointers in your header, but then make sure to add a destructor in order to delete them.

Good luck,

Thanks guys, I made many of those changes and it worked. For personal ease I’m going to stick with my one-file source for now but that will be great when I start programming more advanced things later!