Reputation: 63
I am trying to compile a card game project. Unfortunately I am stuck with a "expected ; before ( token" error, which I could not get my head around. Error occurs in the player header file, which is highlighted.
//player.h
#ifndef PLAYER
#define PLAYER
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "card.h"
using std::vector;
class player{
public:
card getHand(int);
vector <card> gethand();
void printhand();
int gethandsize();
int givecard(deck&,int,int); //**ERROR OCCURS HERE**
bool checkdecision(int* decision);
bool compare(int decision, player& thief);
void steal(card);
void discard(int decision);
protected:
private:
vector <card> h;
};
#endif
//player.cpp
#include "player.h"
player::player(){
}
vector <card> player::gethand(){
return h;
}
card player::getHand(int num){
return h[num];
}
int player::givecard(deck& pool, int hand_index, int &deck_index){
card temp = pool.getd(deck_index);
h.push_back(temp);
pool.pop_back();
}
void player::printhand(){
for(int a = 0; a<h.size(); a++){
cout << h[a].rank_map << " of " << h[a].suit_map << endl;
}
cout << endl;
}
bool player::checkdecision(int decision){
int counter = 0;
for(int a=0; a<h.size(); a++){
if(h[a].rank != decision){
++counter;
}
}
if(counter == h.size()){
cout << "You don't have the card. Start again." << endl;
return true;
}
return false;
}
bool player::compare(int decision, player& thief){
card temp;
int index = 0, initial_hand = h.size();
for(int b = 0; b < initial_hand; b++){
if(h[b].rank != decision){
index++;
}
}
for(int i = 0; i < h.size(); i++){
if(h[i].rank == decision){
cout << "Steal!" << endl;
temp = h[i];
thief.steal(temp);
h.erase(h.begin() + i);
i--;
}
}
if(index == initial_hand){
return false;
}
else if (index != initial_hand){return true;}
}
void player::discard(int decision){
int counter = 0;
for(int k = 0; k < h.size(); k++){
if(h[k].rank == decision){
counter++;
}
}
if(counter == 4){
for(int a = 0; a < h.size(); a++){
if(h[a].rank == decision){
h.erase(h.begin() + a );
a--;
}
}
}
}
void player::steal(card temp){
h.push_back(temp);
}
int player::gethandsize(){
return h.size();
}
player::~player(){}
//cardgames.h
#ifndef CARD_GAMES
#define CARD_GAMES
#include "player.h"
#include "deck.h"
class card_games{
public:
card_games();
void play();
void checkplayer(char thePlayer);
int convert(char);
void distribute();
void setgame(int);
void printhand();
deck getpool();
player getplayer(int);
~card_games();
protected:
int num_player; //number of players
int player_num; //player's turn
private:
deck pool; //pool object
player* p; //array of players
};
#endif
//cardgames.cpp
#include "card_games.h"
#include <iostream>
#include <vector>
using namespace std;
card_games::card_games(){}
void card_games::play(){
char thePlayer;
int temp;
cout << "How many players are playing?" << endl;
cin >> thePlayer;
checkplayer(thePlayer);
temp = convert(thePlayer);
setgame(temp);
distribute();
}
void card_games::checkplayer(char thePlayer){
if(thePlayer < 50 || thePlayer > 54 ){
cout << "Invalid number of players. Please retry." << endl;
cout << endl;
exit(1);
}
}
int card_games::convert(char input){
int value;
player_num = 1;
if(input== '2'){
value = 2;
}
if(input== '3'){
value =3;
}
if(input== '4'){
value = 4;
}
if(input== '5'){
value = 5;
}
if(input == '6'){
value= 6;
}
return value;
}
void card_games::setgame(int temp){
p = new player[temp];
num_player = temp;
}
void card_games::distribute(){
int temp;
int deck_index = 51;
for(int a=0; a < num_player; a++){ //player number
for(int b=0; b < 7; b++){ // hand size
p[a].givecard(pool, b, deck_index);
--deck_index;
}
}
}
player card_games::getplayer(int temp){
return p[temp];
}
deck card_games::getpool(){
return pool;
}
card_games::~card_games(){
}
Thanks for any input.
Upvotes: 1
Views: 77
Reputation: 4778
The prototype of givecard does not match the declared method:
int givecard(deck&,int,int);
Should probably be:
int givecard(deck&,int,int&);
Hope this helps.
Upvotes: 2