如何定义和声明,尽管它被定义和声明?
how to define and declare although it is defined and declared?
我知道这个问题看起来很混乱,但说实话,它不像看起来那样。 我正在建立一个关于无人机的程序(对不起,如果它没有意义( 从这段代码中,我得到错误"(第 116 行(标识符"camrecord"未定义"和"编译器错误 C2065 "(第 116 行(标识符":未声明的标识符",尽管我已经识别并声明了它们?如何解决这个问题? 谢谢
#include<iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string.h>
using namespace std;
void manualMode();
void defaultMode();
void Getdata(double & camrecord, double & Projectframerate);
void calculate(double & camrecord, double & Projectframerate, double & actualframerate);
int speed, timeTofly, operation;
int angle = 90;
int main() {
int mode = 0, part = 3;
double flyLevel;
int obstacleSensor = 0, timer = 3, AccelerometerSensor = 0, tempSensor = 25;
char startPause;
cout << "Drone Flying Technology" << endl;
do {
cout << "Choose Mode: (1)Default, (2)Manual n";
cin >> mode;
if (mode == 1)
defaultMode();
if (mode == 2)
manualMode();
} while (mode == 0);
cout << "Choose how to fly: (1)Upper , (2)Lower , (3)Upper and Lower n";
cin >> part;
switch (part) {
case 1:
case 2:
flyLevel = 0.5;
break;
case 3:
flyLevel = 1;
break;
}
if (obstacleSensor == 0) {
do {
cout << "Press (S) to Start,and swing the propeller." << endl;
cin >> startPause;
cout << "LED is Onn";
while (AccelerometerSensor != flyLevel) {
AccelerometerSensor++;
}
cout << "Flying session Started! Time Left:" << timeTofly << endl;
cout << "Eagle eye Operation Started!n";
timeTofly = timeTofly / 2;
cout << "Crusing mode initiate Time Left:" << timeTofly << endl;
timeTofly = timeTofly / 2;
cout << "Free fly commenced Time Left:" << timeTofly << endl;
timeTofly = 0;
startPause = 'P';
} while ((startPause == 's') || (startPause == 'S'));
}
cout << "End!nLED is Off";
return 0;
}
void manualMode() {
cout << "Enter drone speed (knot) n";
cin >> speed;
cout << "Enter Time to fly: n";
cin >> timeTofly;
cout << "Choose Operation: (1)Fully manual, (2)Normal Orientation, (3)Free orientation, (4)FPV racing, (5)Alln";
cin >> operation;
}
void defaultMode() {
int howtofly;
cout << "how to fly: (1)Circle, (2)Altitude Hold, (3)Free orientation";
cin >> howtofly;
switch (howtofly) {
case 1:
speed = 30;
timeTofly = 3;
break;
case 2:
speed = 40;
timeTofly = 3;
break;
case 3:
speed = 60;
timeTofly = 3;
break;
}
char name[25];
char id[5];
float m1, m2, m3, m4, m5;
ofstream outputFile("droneinfo.txt", ios::out);
cout << "Please enter object you want to record,drone id imei number and your 5 preferred video fps:n";
cout << "nPress <ctrl> + z to stop. n";
while (cin >> id >> name >> m1 >> m2 >> m3 >> m4 >> m5)
{
outputFile << id << " " << name << " " << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
}
double fps = 0.0;
double Projectframerate = 0.0;
double actualframerate, out = 0;
Getdata(camrecord, Projectframerate);
calculate(camrecord, Projectframerate, actualframerate);
cout << "The actual frame rate is =" << actualframerate << " f/sn";
}
void Getdata(double& camrecord, double& Projectframerate) {
cin >> camrecord;
cin >> Projectframerate;
cout << "Please entern Recording frame rate =" << camrecord << "f/s ,ndesired frame rate="
<< Projectframerate << "f/sn";
}
//-------------------//
void calculate(double& camrecord, double& Projectframerate, double& actualframerate) {
actualframerate = camrecord / Projectframerate;
}
//-------------------//
因此,当您想要输入变量并对其进行修改时,将使用引用作为参数。查看void Getdata(double& camrecord, double& Projectframerate)
,您是说Getdata
采用摄像机记录和投影帧速率,读取这些值并对其进行修改,以便调用方可以使用新值。
查看代码,似乎并没有Getdata
实际上是在读取输入值。所以存在不一致。
为了与方法的实现保持一致,方法Getdata
不应接受任何参数 - 而只返回它们。现在,您不能返回两个参数,但可以将它们打包到一个结构中并返回:
struct Data
{
double camrecord;
double Projectframerate;
};
Data Getdata();
然后,Getdata
的定义可以是:
Data getData()
{
Data data;
cin >> data.camrecord;
cin >> data.Projectframerate;
cout << "Please entern Recording frame rate =" << data.camrecord << "f/s ,ndesired frame rate="
<< data.Projectframerate << "f/sn";
return data;
}
同样可以为calculate
.
相关文章:
- 如何在C++中声明/定义相互依赖的模板?
- C++概念是否允许我的类在声明/定义中指定它满足某些概念?
- MSVC:无法识别的模板声明/定义(使用 Clang/GCC 编译)
- 我可以重用同一个模板来声明/定义多个东西吗(而不复制模板代码)
- C++-模板类中模板函数的单独声明/定义
- 在C 中使用继承时,请避免使用未缴纳的函数声明/定义
- C++模板能否确定所声明/定义的实例是否为常量
- 如何在程序中声明/定义一次并在两个类中使用映射列表
- LBNF,C函数声明/定义,减少冲突
- 声明/定义返回具有自动返回类型的 valarray 的函数时的隔离错误
- #用{}和声明定义混淆
- CTOR 声明/定义中接受的 const 限定符(LLVM 错误?)
- C++ 从一个源文件中声明/定义的变量从另一个源文件访问另一个源文件
- 无法识别的模板声明/定义
- 只在.cpp中声明/定义静态方法可以吗
- 声明/定义自定义类定制对象的正确方法
- typedef声明定义未命名类时链接失败
- 用visual c++实现COM对象的声明/定义和实例化
- VS 2012中的显式模板声明/定义
- 命名空间内的友元函数声明/定义