这是带有问题的代码:
#ifndef WEAPONS_H_INCLUDED
#define WEAPONS_H_INCLUDED
#include "Battleship header.h"
void Player::torpedo(string enemyEvtTracker[][10], string myhitboard[][10])
{
string bcn; //board column number
cout << "Enter board column number (1-9): "; cin >> bcn; flush();
if(bcn!="1"&&bcn!="2"&&bcn!="3"&&bcn!="4"&&bcn!="5"&&bcn!="6"&&bcn!="7"&&bcn!="8"&&bcn!="9")
{cout <<endl<< "That is not a valid number.";}
return;
}
#endif // WEAPONS_H_INCLUDED
这是类Player:
#ifndef BATTLESHIPPLAYERCLASS_H_INCLUDED
#define BATTLESHIPPLAYERCLASS_H_INCLUDED
using namespace std;
class Player // define a class for a player
{
void torpedo(string enemyEvtTracker[10][10], string myhitboard[10][10]);
void cannon();
void scatter();
void menu();
friend int main(int, char*[]); //Let main access the protected members
friend int routine_END(void);
public:
void displaydata()
{cout << money << endl << gunpowder << endl << ammo_cannon << endl << ammo_4hit << endl;}
string savename;
int gunpowder;
int ammo_cannon;
int ammo_4hit; string gun_4;
int ammo_scatter; string gun_s;
int money;
Player(string name){money=18000; gunpowder=100;ammo_cannon=20; ammo_4hit=0; ammo_scatter=0; gun_4="OFF"; gun_s="OFF";playername=name;} //Define the constructor
void simplegame(void) {gunpowder=99999999; ammo_cannon=999999999; ammo_scatter=4; gun_s="ON";}
void getname(string *playername, int option)
{
if (option==1)
{cout << "Enter your name here player 1:"; cin >> *playername;}
else {cout << "Enter your name here player 2:"; cin >> *playername;}
}
string playername;
char mainRowGuess;
int check_transaction (int mymoney, int moneyowed)
{
if (mymoney-moneyowed<<0) {return 0;}
else {return 1;}
}
void change_Answer_to_number(char row,int* outputRow)
{
if (row=='A'||row=='a'){*outputRow =1;}
else if (row=='B'||row=='b'){*outputRow =2;}
else if (row=='C'||row=='c'){*outputRow =3;}
else if (row=='D'||row=='d'){*outputRow =4;}
else if (row=='E'||row=='e'){*outputRow =5;}
else if (row=='F'||row=='f'){*outputRow =6;}
else if (row=='G'||row=='g'){*outputRow =7;}
else if (row=='H'||row=='h'){*outputRow =8;}
else if (row=='I'||row=='i'){*outputRow =9;}
else {*outputRow = 0;}
}
void changeCharToNumber(char row, int* outputRow)
{
if (row=='1'){*outputRow=1;}
else if (row=='2'){*outputRow=2;}
else if (row=='3'){*outputRow=3;}
else if (row=='4'){*outputRow=4;}
else if (row=='5'){*outputRow=5;}
else if (row=='6'){*outputRow=6;}
else if (row=='7'){*outputRow=7;}
else if (row=='8'){*outputRow=8;}
else if (row=='9'){*outputRow=9;}
else {cout << "Unexpected Error." << endl; *outputRow=0;}
}
char airRowStart; char airColStart; char aircraftDirec;
char destRowStart; char destColStart; char destroyerDirec;
char subRowStart; char subColStart; char subDirec;
char patrolStart; char patrolDirec;
/// START MENU FUNCTION
void error_money(void) {cout << "Not enough money!";}
char startRowAircraftCarrier;
char startRowDestroyer;
char startRowSub;
char startRowPatrolBoat;
friend int routine_END (void);
friend void menu (int* gunpowder, int* ammo_cannon, int* ammo_4hit, int* ammo_scatter, int* money, string* gun_4, string* gun_s);
};
#endif // BATTLESHIPPLAYERCLASS_H_INCLUDED
这将生成以下构建日志...
-------------- Build:Advanced Battleship Obj中的调试
[50.0%]编译:main.cpp C:\ Advanced_Battleship_Revised_5111 \ main.cpp中:32: 警告:忽略#pragma评论 文件包括 C:\ Advanced_Battleship_Revised_5111 \ /imputoutput.h:9, 来自C:\ Advanced_Battleship_Revised_5111 \ / Battleship header.h:3, 来自C:\ Advanced_Battleship_Revised_5111 \ main.cpp:25: C:\ Advanced_Battleship_Revised_5111 \ /BattleshipPlayerClass.h:74: 警告:'int routine_END()'是 已经是'玩家'班的朋友了 C:\ Advanced_Battleship_Revised_5111 \ /BattleshipPlayerClass.h: 在成员函数'int Player :: check_transaction(int,int)': C:\ Advanced_Battleship_Revised_5111 \ /BattleshipPlayerClass.h:33: 警告:建议左右括号 ' - '在'&lt;&lt;'在包含的文件中 C:\ Advanced_Battleship_Revised_5111 \ main.cpp中:27: C:\ Advanced_Battleship_Revised_5111 \ /BattleshipMenu.h: 在成员函数'void 球员::菜单()“: C:\ Advanced_Battleship_Revised_5111 \ /BattleshipMenu.h:118: 警告:标签'GUNPOWDER_MENU_1' 已定义但未使用 C:\ Advanced_Battleship_Revised_5111 \ /BattleshipMenu.h:166: 警告标签 'CIN_WEAPON_OPTION_SCATTER_CANNON' 已定义但未使用包含在文件中 从 C:\ Advanced_Battleship_Revised_5111 \ main.cpp中:30: C:\ Advanced_Battleship_Revised_5111 \ /weapons.h: 在全球范围内: 的&GT; C:\ Advanced_Battleship_Revised_5111 \ /weapons.h:5:错误:声明 'enemyEvtTracker'为多维 数组必须有所有的边界 尺寸除了第一个 C:\ Advanced_Battleship_Revised_5111 \ /weapons.h:5:错误:预期')'之前','令牌 C:\ Advanced_Battleship_Revised_5111 \ /weapons.h:5:错误:预期的构造函数, 析构函数,或类型转换之前 ','令牌 C:\ Advanced_Battleship_Revised_5111 \ /weapons.h:5:错误:预期的构造函数, 析构函数,或类型转换之前 'myhitboard'流程以终止 状态1(0分,1秒)4 错误,5个警告
答案 0 :(得分:3)
Player::torpedo(string enemyEvtTracker[10][10], string myhitboard[10][10])
{
//..
}
这是成员函数的定义。 声明在哪里?
我的猜测是,在声明中你没有提到数组的大小,就像你在定义中所做的那样。看来你写的只是enemyEvtTracker [][]
?请参阅Player
类的定义,并验证您如何在其中声明torpedo
成员函数。