我对C++相当陌生,从未创建过我自己的类,直到今天。我不喜欢发布代码供人们正常查看,但我处于紧急的最后期限之内,需要编译我的代码。我得到三个错误:C++错误创建类
- 错误:比以前的声明`RobotDeadReckoner :: RobotDeadReckoner()掷() '
在该行 - 多标记 - 错误:RobotDeadReckoner::RobotDeadReckoner()' throws different exceptions - error: definition of implicitly-declared
RobotDeadReckoner :: RobotDeadReckoner的声明()'
-error:没有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.您既没有 - 让你的getter描述他们得到的东西。 – KevinDTimm 2012-02-20 21:52:27