Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   An error when inheriting Joystick (http://www.chiefdelphi.com/forums/showthread.php?t=113351)

MathMaven 12-02-2013 17:24

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.


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

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