Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Issues with a header file (http://www.chiefdelphi.com/forums/showthread.php?t=77744)

Happyisgood 25-06-2009 16:58

Issues with a header file
 
2 Attachment(s)
Hey!

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!

Thanks!
Nick

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

Pat Fairbank 26-06-2009 01:53

Re: Issues with a header file
 
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:
Code:

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.

RyanCahoon 26-06-2009 04:09

Re: Issues with a header file
 
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,
--Ryan

Happyisgood 26-06-2009 10:52

Re: Issues with a header file
 
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!

Thanks!
Nick


All times are GMT -5. The time now is 13:53.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi