View Single Post
  #1   Spotlight this post!  
Unread 12-02-2013, 17:24
MathMaven MathMaven is offline
Registered User
AKA: Elisha Sword
FRC #3175 (Knight Vision)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Michigan
Posts: 50
MathMaven is on a distinguished road
An error when inheriting Joystick

There are cases in our code when we use the negated value of the Y-axis for a Joystick. I know this is (really) easy to do, but for convenience, I'd love to extend the Joystick class to include a member function that would do it automatically—I think the resultant code would read a little more intuitively.

So I tried writing this:

Code:
#include "WPILib.h"

// some code...

class MyNewAndImprovedJoystickClass : public Joystick
{
public:
	virtual float GetNegativeY() //
	{
		return -GetY();
	}
};

// more code...
But WindRiver returned the following error:

Quote:
C:/WindRiver/2013/SimpleTemplate/MyRobot.cpp:33: error: base `Joystick' with only non-default constructor in class without a constructor
And, well, I'm not sure what that means.

I understand that this issue on its own is an unimportant one. But I'm doing something wrong, and I'd like to know why. Besides, knowing more about C++ and WPILib can't hurt me.

Edit:
I found a WPILib-extending library that includes an extended Joystick class. After looking there, I tried rewriting the class as follows, and built without error:

Code:
class MyNewAndImprovedJoystickClass : public Joystick
{
public:
	MyNewAndImprovedJoystickClass(UINT32 port) : Joystick(port) {}

	virtual float GetYAdj()
	{
		return -GetY();
	}
};
I haven't tested this on the robot yet, but here's hoping.
__________________
—Elisha Sword

2010–13: FRC Team 3175 (Knight Vision), student, lead programmer
2012–13: FRC Team 3175 (Knight Vision), lead website designer
2014: FRC Team 3175 (Knight Vision), programming mentor

“Who has not been amazed to learn that the function y = e^x, like a phoenix rising from its own ashes, is its own derivative?”
—Francois le Lionnais

Last edited by MathMaven : 12-02-2013 at 17:56. Reason: I may have found the solution. (Also, forgot to make my functions public. Heh heh.)
Reply With Quote