c++ 函数定义不声明参数
c++ Function Definition does not declare parameters
我在C++项目中遇到编译错误。在我朋友的计算机上,我没有收到任何错误,但在我计算机上,我得到以下信息:
129 - "Function Definition does not declare parameters "
线
137 - "'seats' was not declared in this scope"
线
我在 Windows 7 上运行代码::块 10.05。
这是我的代码(行号由注释指示):
#include <iostream>
#include "Seat.h"
using namespace std;
class Plane
{
public:
int viewSeat(int sNum) {
if (seats[sNum].isFree()) {
return 0;
} else {
//cout << "Debug (Plane::viewSeat(sNum) called)";
string seatMess = "";
switch (seats[sNum].getState()) {
case 1:
seatMess = " is reserved for ";
break;
case 2:
seatMess = " has been checked in by ";
break;
}
cout << "(X) Seat ";
cout << seats[sNum].getCode();
cout << seatMess;
cout << seats[sNum].getFName() << " " << seats[sNum].getLName() << "n";
return 1;
}
}
void viewAll() {
for (int x = 0; x < numOfSeats; x++) {
if ((seats[x].getState() == 0)) {
cout << "Seat " << seats[x].getCode() << " is freen";
} else {
viewSeat(x);
}
}
}
void viewFree() {
int freeSeats = 0;
for (int x = 0; x < numOfSeats; x++) {
if ((seats[x].getState() == 0)) {
cout << "Seat " << seats[x].getCode() << " is freen";
freeSeats++;
}
}
cout << "Found " << freeSeats << " free seatsn";
}
void freeSeat(int sNum) {
seats[sNum].emptySeat();
}
string getCode(int sNum) {
return seats[sNum].getCode();
}
int reserveSeat(int sNum, string fName, string lName, int age, int cType, string business = "") {
if (seats[sNum].isFree()) {
seats[sNum].setFName(fName);
seats[sNum].setLName(lName);
seats[sNum].setAge(age);
seats[sNum].setType(cType);
seats[sNum].setState(1);
seats[sNum].setBusiness(business);
return 1;
} else {
return 0;
}
}
int checkSeat(string lName, string seatCode) {
int found = 0;
for (int x = 0; x < (sizeof(seats) / sizeof(Seat)); x++) {
if ((seats[x].getCode() == seatCode) && (seats[x].getLName() == lName)) {
found = 1;
seats[x].setState(2);
return 1;
}
}
return 0;
}
int calcTake() {
int seatPrice = 5;
int totalTake, totalSeats = 0, totalWestern = 0, totalBusiness = 0, totalStandard = 0;
for (int x = 0; x < numOfSeats; x++) {
if ((seats[x].getState() != 0)) {
int cType = seats[x].getType();
int thisSeat;
if (cType == 1) {
// discount for western`
thisSeat = 0.75 * seatPrice;
totalWestern++;
} else if (cType == 2) {
// discount for business
thisSeat = 0.8 * seatPrice;
totalBusiness++;
} else {
thisSeat = 0.95 * seatPrice;
totalStandard++;
}
totalTake = totalTake + thisSeat;
totalSeats++;
}
}
return totalTake;
}
int isFree(int sNum) {
if (seats[sNum].isFree()) {
return 1;
} else {
return 0;
}
}
private:
// Line 129 ("Function Definition does not declare parameters"):
Seat seats[32] { {"1A"}, {"1B"}, {"1C"}, {"1D"},
{"2A"}, {"2B"}, {"2C"}, {"2D"},
{"3A"}, {"3B"}, {"3C"}, {"3D"},
{"4A"}, {"4B"}, {"4C"}, {"4D"},
{"5A"}, {"5B"}, {"5C"}, {"5D"},
{"6A"}, {"6B"}, {"6C"}, {"6D"},
{"7A"}, {"7B"}, {"7C"}, {"7D"},
{"8A"}, {"8B"}, {"8C"}, {"8D"}
};
// Line 137 ("'seats' was not declared in this scope"):
int numOfSeats = sizeof(seats) / sizeof(Seat);
};
我想你错过了=
Seat seats[32] = { {"1A"}, {"1B"}, {"1C"}, {"1D"},..
相关文章:
- 在C++中声明一个函数时,它需要有函数本身的参数吗
- 对可变参数使用声明.如何选择正确的功能
- Arduino C++在构造函数中用参数声明对象数组
- 标准::向量声明中使用的模板参数
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 将类型声明为类型模板参数的模板参数的一部分是否合法?
- 构造函数/函数声明参数列表中的统一初始化
- C++ - 声明指向返回任何类型并获取任意数量参数的函数的指针
- 带参数的数据结构的全局声明
- C++使用默认模板参数键入别名和转发声明
- 警告:忽略模板参数上的属性..在 std::unique_ptr (-wignore 属性)的声明中
- C++声明模板参数阴影模板参数错误
- "extern"声明以及带有和不带参数列表的类模板实例的后续定义
- 如何使用参数声明实例?
- 采用nulltpr_t的构造函数:函数定义不声明参数
- c++ 函数定义不声明参数
- 在循环范围之外声明参数是否更有效?
- 在linux下使用mingw交叉编译器声明"参数"中的两种或多种数据类型
- Clang Format多行函数声明参数问题
- 氧-声明参数为可选的