here is the code with the problem:
#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
here is the class 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
and this generates the following build log...
-------------- Build: Debug in Advanced Battleship Obj
[ 50.0%] Compiling:开发者_JS百科 main.cpp C:\Advanced_Battleship_Revised_5111\main.cpp:32: warning: ignoring #pragma comment In file included from C:\Advanced_Battleship_Revised_5111\/imputoutput.h:9, from C:\Advanced_Battleship_Revised_5111\/Battleship header.h:3, from C:\Advanced_Battleship_Revised_5111\main.cpp:25: C:\Advanced_Battleship_Revised_5111\/BattleshipPlayerClass.h:74: warning: 'int routine_END()' is already a friend of class 'Player' C:\Advanced_Battleship_Revised_5111\/BattleshipPlayerClass.h: In member function 'int Player::check_transaction(int, int)': C:\Advanced_Battleship_Revised_5111\/BattleshipPlayerClass.h:33: warning: suggest parentheses around '-' inside '<<' In file included from C:\Advanced_Battleship_Revised_5111\main.cpp:27: C:\Advanced_Battleship_Revised_5111\/BattleshipMenu.h: In member function 'void Player::menu()': C:\Advanced_Battleship_Revised_5111\/BattleshipMenu.h:118: warning: label 'GUNPOWDER_MENU_1' defined but not used C:\Advanced_Battleship_Revised_5111\/BattleshipMenu.h:166: warning: label 'CIN_WEAPON_OPTION_SCATTER_CANNON' defined but not used In file included from C:\Advanced_Battleship_Revised_5111\main.cpp:30: C:\Advanced_Battleship_Revised_5111\/weapons.h: At global scope: > C:\Advanced_Battleship_Revised_5111\/weapons.h:5: error: declaration of 'enemyEvtTracker' as multidimensional array must have bounds for all dimensions except the first C:\Advanced_Battleship_Revised_5111\/weapons.h:5: error: expected ')' before ',' token C:\Advanced_Battleship_Revised_5111\/weapons.h:5: error: expected constructor, destructor, or type conversion before ',' token C:\Advanced_Battleship_Revised_5111\/weapons.h:5: error: expected constructor, destructor, or type conversion before 'myhitboard' Process terminated with status 1 (0 minutes, 1 seconds) 4 errors, 5 warnings
Player::torpedo(string enemyEvtTracker[10][10], string myhitboard[10][10])
{
//..
}
This is the definition of the member function. Where is the declaration?
My guess is that in the declaration you've not mentioned the size of the array, as you did in the definition. It seems you've written simply enemyEvtTracker [][]
? See the definition of Player
class, and verify how you've declared torpedo
member function in it.
精彩评论