parameter error

im working in class and trying to open and print out from a file heres the error im getting
1
2
game.cpp: In member function âbool Game::Fill(std::string)â:
game.cpp:55: error: expected primary-expression before â&â token


and the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include "game.h"
using namespace std;

Game::Game()
{

   HomeScore = 0;
   RivalScore = 0;
}

Game::Game (const Game &OtherGame)
{
   rival = OtherGame.rival;
   RivalScore = OtherGame.RivalScore;
   HomeScore = OtherGame.HomeScore;
}

Game::~Game()
{
}
bool Game::GetData(ifstream &Input)
{
  if(Input>>rival>>RivalScore>>HomeScore)
         success = true;
  else
         success = false;
  return success;
}

void Game::SetInfo(const string Opponent, const int OScore, const int HScore)
{
rival = Opponent;
RivalScore = OScore;
HomeScore = HScore;
}

bool Game::Fill (const string Filename)
{
ifstream Din;


 Din.open(Filename.c_str());
   if (!Din)
   {
        success = false;
   }
   else
   {
      while(success != false)
      {
         GetData(ifstream &Filename);
         numgames++;
      }
        success = true;
   }
 Din.close();
 return success;
}
GetData(&Filename); line 55
this was already pointed out to you in your last thread, you really need to pay attention to what people tell you on here.

you dont need to pass a type to functions only the name of the variable.
But in saying that line 25 will also not work as ifstream is not a data type, you just will have to put the the few lines in that function into line 55-58 or you can see if the scope will work within that function simply by having bool Game::GetData() { ....etc }

EDIT:
also naming/case convention is a bit off... typically you should use camel case for functions and variables starting with lowercase, and uppercase for constants, and camel case for classes.

eg:
1
2
3
4
class Game
function getData();
string thisIsAString="This is a string";
const int GAME_LENGTH=1000;
Last edited on
Well, that's actually a matter of style. Choose whatever style you like, as long you are consistent is the general consensus.
You sure? I thought it was standard convention.
well i know it is in Java, but figured c was the same. even though other forms work perfectly well in both languages, we have standards in place so other people know what the hell your code is doing, and vice versa.

string ThIsIsAsTrInGvArIaBlE="This is a string";

is also valid.... but would it be ok to use often? absolutely not :P
Last edited on
my teacher marks off points for bad variable names. And I think "thisIsAString" would be one of those bad variable names.
it was a case example.... not much of an example of camel case if I only had called it " str1 " , " input " or some such

additionally, naming is very important and your teacher is obviously somewhat experienced. But the naming of variables is only important for 1 very good reason... The people or other people reading your code need to understand your variable names. ( int a=34, b=23452, c=323, d=874; are bad examples of naming)

Are you trying to tell me you don't know or understand what "thisIsAString" is? it's pretty obvious, so in this case it's a perfect name for it.
Last edited on
Topic archived. No new replies allowed.