Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;创建类时出错 我对C++是相当新的,直到今天我才创造出一个自己的类。我不喜欢发布代码供人们正常查看,但我的最后期限很紧,需要对代码进行编译。我有三个错误:_C++_Class - Fatal编程技术网

C++;创建类时出错 我对C++是相当新的,直到今天我才创造出一个自己的类。我不喜欢发布代码供人们正常查看,但我的最后期限很紧,需要对代码进行编译。我有三个错误:

C++;创建类时出错 我对C++是相当新的,直到今天我才创造出一个自己的类。我不喜欢发布代码供人们正常查看,但我的最后期限很紧,需要对代码进行编译。我有三个错误:,c++,class,C++,Class,-错误:比上一个声明“RobotDeadEnguerer::RobotDeadEnguerer()throw()”更高” -这条线上有多个标记 -错误:RobotDeadRecugener::RobotDeadRecugener()的声明引发不同的错误 例外情况 -错误:隐式声明的定义RobotDeadRecugener::RobotDeadRecugener() -错误:无RobotDeadAccounter::~RobotDeadAccounter()'类中声明的成员函数RobotDeadA

-错误:比上一个声明“RobotDeadEnguerer::RobotDeadEnguerer()throw()”更高”

-这条线上有多个标记 -错误:
RobotDeadRecugener::RobotDeadRecugener()的声明引发不同的错误
例外情况
-错误:隐式声明的定义
RobotDeadRecugener::RobotDeadRecugener()

-错误:无<代码>RobotDeadAccounter::~RobotDeadAccounter()'类中声明的成员函数<代码>RobotDeadAccounter'

代码如下:

#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

}
#包括
#包括“WPILib.h”
类机器人推算器
{//Get();
pi=atan(1)*4;
}
浮点机器人死亡推算器::getX()
{
float x=车轮半径*cos(getHeading())*(encoderTicks1+encoderTicks2)*(pi/滴答箭头);
返回x;
}
浮动机器人死亡推算器::getY()
{
浮动y=车轮半径*sin(getHeading())*(编码器时钟1+编码器时钟2)*(pi/滴答箭头);
返回y;
}
浮动机器人死亡推算器::getHeading()
{
浮动航向=(2*pi)*(车轮半径/轴宽中心到中心)*(编码器芯片S1-编码器芯片S2);
返回航向;
}
机器人死亡推算器::~robotdeadrecogner()
{ //
隐式声明的RobotDeadRecugener::RobotDeadRecugener()的定义

这是最重要的线索。您尚未声明
RobotDeadRecugener()
的构造函数,您只定义了它。如果您不提供默认构造函数,编译器将为您提供一个,因此“隐式声明”。请参阅

没有RobotDeadEnguerer::~RobotDeadEnguerer()'在ClassRobotDeadEnguerer中声明的成员函数'

析构函数也是一样

将以下内容添加到类声明的(
public:
部分):

RobotDeadReckoner();
virtual ~RobotDeadReckoner();

您应该首先在类定义中声明析构函数(和构造函数)

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;
};
类机器人死亡推算器

{/文章的第一部分是类定义,它应该包含所有成员的声明。构造函数和析构函数。这些在类定义中不存在

 class Robot{   declarations. }; // end of class definition
以下内容在上面的类中没有相应的声明

RobotDeadReckoner::RobotDeadReckoner()
此外,您还应该将类放在.h文件中

RobotDeadReckoner::RobotDeadReckoner()
在.cpp文件中

所以你的班级应该是这样的:

class RobotDeadReckoner{
     RobotDeadReckoner();
     ~RobotDeadReckoner();
 etc...

您既没有声明
robotdeadugener
构造函数也没有声明析构函数,因此无法使用
robotdeagener::robotdeagener()
robotdeagener::~robotdeagener()
进一步定义它们

在类声明中,添加

RobotDeadReckoner();
~RobotDeadReckoner();

然后将编译进一步的定义。

您只能为用户定义的构造函数和析构函数提供实现:

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;
};

如果您没有为类声明构造函数或析构函数,编译器将自动为您生成一个默认构造函数或析构函数,您无法实现它。

请注意getX()和getY()的约定假设你有一个名为X的变量和另一个名为Y的变量。你都没有-让你的获取者描述他们得到了什么。谢谢!我不明白这意味着什么,但在我看到它后这是很明显的…@Jacob9706:很乐意帮忙。欢迎来到StackOverflow:)