Go to Post If FIRST isn't your life, then you're doing something wrong! - BandChick [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:57.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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