2 Replies - 341 Views - Last Post: 01 April 2010 - 07:43 PM Rate Topic: -----

#1 Ranger475  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 16-March 10

error with function definition vrs initialization

Posted 01 April 2010 - 07:28 PM

Following a book from the library on C++ programming, unfortunately the CD that goes with the book is unavailable. While working on the chapter with the simple blackjack program, I entered all of the code the book gave me and tried to compile. I was missing a function for "whoWins", checked the function prototype in the header file and tried to write a function to match it and perform the function needed. Now when I try to compile I am getting and error c2448 - 'identifier' : function-style initializer appears to be a function definition. listed below are the code from both the header and source file but I don't understand the reason for the error. Can someone explain?

from the headerfile
//Output functions, sending messaages to the user
void announceCard( int theCard);
void announceHand( int theHand);
void announceResult( bool side, int theHand);
void whoWins(int playerHand, int houseHand);




from the sourcefile
void whoWins(playerHand, houseHand)
{
	if ((playerHand > houseHand) && (playerHand <= 21))
	{cout << "Player Wins" << endl;}
	else if ((playerHand > houseHand) && (playerHand > 21))
	{cout << "House Wins" << endl;}
	else {cout << "House Wins" << endl;}
return;
}



Is This A Good Question/Topic? 0
  • +

Replies To: error with function definition vrs initialization

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: error with function definition vrs initialization

Posted 01 April 2010 - 07:35 PM

void whoWins(playerHand, houseHand)

Specify the types of the variables:

void whoWins(int playerHand, int houseHand)

Was This Post Helpful? 1
  • +
  • -

#3 Ranger475  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 16-March 10

Re: error with function definition vrs initialization

Posted 01 April 2010 - 07:43 PM

Ok, I thought because the playerHand & houseHand were declared as int in the prototype I didn't have to specify them again. That fixed the error though so thank you, spent about 45 minutes writing and rewriting code, but didn't try that :-/ Got to love learning new languages.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1