0

I am fairly new to c++ and have never created a class of my own until today. I don't like to post up code for people to review normally but I am on a tight deadline and need to get my code compiling. I get three errors:

-error: than previous declaration `RobotDeadReckoner::RobotDeadReckoner() throw ()'

-Multiple markers at this line - error: declaration of RobotDeadReckoner::RobotDeadReckoner()' throws different exceptions - error: definition of implicitly-declaredRobotDeadReckoner::RobotDeadReckoner()'

-error: no RobotDeadReckoner::~RobotDeadReckoner()' member function declared in classRobotDeadReckoner'

The code is as follows:

#include <cmath>
#include "WPILib.h"


class RobotDeadReckoner
{//<---------------------Error
public:
    float getX();
    float getY();
    float getHeading();
private:
    Encoder *encoder1;//Encoder1 (Left Transmision while looking from the back)
    Encoder *encoder2;//Encoder2 (Right Transmision while looking from the back)
    int wheelRadius;//Wheel Radius (Center Wheel)
    float axleWidthCenterToCenter;
    int encoderTicksPerRotation;
    int transmitionSprocketTeeth;
    int wheelSprocketTeeth;
    int ticksPerRotation; //ticks per rotation of wheel
    float encoderTicks1;
    float encoderTicks2;
    float pi;
};

RobotDeadReckoner::RobotDeadReckoner()
{//<---------------------Error
    wheelRadius = 4;//Wheel Radius (Center Wheel)
    axleWidthCenterToCenter = 30+(7/8);
    encoderTicksPerRotation = 360;
    transmitionSprocketTeeth = 12;
    wheelSprocketTeeth = 26;
    ticksPerRotation = (wheelSprocketTeeth/transmitionSprocketTeeth)*encoderTicksPerRotation; //ticks per rotation of wheel

    encoderTicks1 = encoder1->Get();
    encoderTicks2 = encoder2->Get();

    pi = atan(1)*4;
}

float RobotDeadReckoner::getX()
{
    float x = wheelRadius*cos(getHeading())*(encoderTicks1+encoderTicks2)*(pi/ticksPerRotation);
    return x;
}

float RobotDeadReckoner::getY()
{
    float y = wheelRadius*sin(getHeading())*(encoderTicks1+encoderTicks2)*(pi/ticksPerRotation);
    return y;
}

float RobotDeadReckoner::getHeading()
{
    float heading = (2*pi)*(wheelRadius/axleWidthCenterToCenter)*(encoderTicks1-encoderTicks2);
    return heading;
}

RobotDeadReckoner::~RobotDeadReckoner()
{ //<---------------------Error

}

I am sure it is something stupid simple I don't know about c++ but any help would be appreciated!

Jacob9706
  • 21
  • 6
  • 1
    Note that the convention for getX() and getY() would assume you had a variable named X and another named Y. You have neither - make your getters describe what they get. – KevinDTimm Feb 20 '12 at 21:52

5 Answers5

1

definition of implicitly-declared RobotDeadReckoner::RobotDeadReckoner()

This is the biggest clue. You haven't declared the constructor for RobotDeadReckoner(), you've only defined it. If you don't provide a default constructor, the compiler will provide one for you, hence "implicitly-declared". See What is The Rule of Three? .

no RobotDeadReckoner::~RobotDeadReckoner()' member function declared in classRobotDeadReckoner'

Same again for the destructor.

Add the following to (public: section of) your class declaration:

RobotDeadReckoner();
virtual ~RobotDeadReckoner();
Community
  • 1
  • 1
johnsyweb
  • 136,902
  • 23
  • 188
  • 247
1

The first part of your post is a class definition, it should contain declarations of all members. Constructors and destructors. These are not present in you class definition.

 class Robot{   declarations. }; // end of class definition

The following does not have a corresponding declaration in your class above.

RobotDeadReckoner::RobotDeadReckoner()

Also you should put your class in a .h file and the

RobotDeadReckoner::RobotDeadReckoner()

in a .cpp file.

So your class should look like:

class RobotDeadReckoner{
     RobotDeadReckoner();
     ~RobotDeadReckoner();
 etc...
Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67
0

You should declare destructor (and constructor) in the class definition first.

class RobotDeadReckoner
{//<---------------------Error
public:
  RobotDeadReckoner();
  ~RobotDeadReckoner(); // <--- HERE
    float getX();
    float getY();
    float getHeading();
private:
    Encoder *encoder1;//Encoder1 (Left Transmision while looking from the back)
    Encoder *encoder2;//Encoder2 (Right Transmision while looking from the back)
    int wheelRadius;//Wheel Radius (Center Wheel)
    float axleWidthCenterToCenter;
    int encoderTicksPerRotation;
    int transmitionSprocketTeeth;
    int wheelSprocketTeeth;
    int ticksPerRotation; //ticks per rotation of wheel
    float encoderTicks1;
    float encoderTicks2;
    float pi;
};
Dmitriy Kachko
  • 2,804
  • 1
  • 19
  • 21
0

You have declared neither the RobotDeadReckoner constructor nor destructor, so you cannot define them further down with RobotDeadReckoner::RobotDeadReckoner() and RobotDeadReckoner::~RobotDeadReckoner().

Inside the class declaration, add

RobotDeadReckoner();
~RobotDeadReckoner();

and then the definitions further down will compile.

Johann Gerell
  • 24,991
  • 10
  • 72
  • 122
0

You can only provide implementations for user-defined constructors and destructors:

class RobotDeadReckoner
{
public:
   //declare constructor and destructor
   RobotDeadReckoner();
   ~RobotDeadReckoner();
public:
    float getX();
    float getY();
    float getHeading();
private:
    Encoder *encoder1;//Encoder1 (Left Transmision while looking from the back)
    Encoder *encoder2;//Encoder2 (Right Transmision while looking from the back)
    int wheelRadius;//Wheel Radius (Center Wheel)
    float axleWidthCenterToCenter;
    int encoderTicksPerRotation;
    int transmitionSprocketTeeth;
    int wheelSprocketTeeth;
    int ticksPerRotation; //ticks per rotation of wheel
    float encoderTicks1;
    float encoderTicks2;
    float pi;
};

If you don't declare a constructor or a destructor for your class, the compiler will automatically generate a default one for you, which you can't implement.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625