Я довольно новичок в C++ и никогда не создавал свой собственный класс до сегодняшнего дня. Мне не нравится публиковать код для людей, чтобы нормально их просматривать, но я нахожусь в сжатом сроке и должен получить компиляцию кода. Я получаю три ошибки:C++ Ошибка создания класса
-ошибка: по сравнению с предыдущей декларации `RobotDeadReckoner :: RobotDeadReckoner() бросок() '
-Несколько маркеры на этой линии - ошибка: декларации RobotDeadReckoner::RobotDeadReckoner()' throws different exceptions - error: definition of implicitly-declared
RobotDeadReckoner :: RobotDeadReckoner()'
-ошибка: НЕТ RobotDeadReckoner::~RobotDeadReckoner()' member function declared in class
RobotDeadReckoner»
код выглядит следующим образом:
#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
}
Я уверен, что это нечто глупое, я не знаю о C++, но любая помощь будет оценена!
Обратите внимание, что соглашение для getX() и getY() предполагает, что у вас есть переменная с именем X и другая с именем Y. У вас нет ни одного - заставить ваши геттеры описывать, что они получают. – KevinDTimm