error outputting with classes

Im trying to read from a file using classes and objects. i keep getting this error


1
2
main.cpp:16: error: no matching function for call to ‘Game::fillGame()’
Game.h:41: note: candidates are: bool Game::fillGame(std::ifstream&)


here is code that goes with the error


1
2
3
4
//Game.h

 bool fillGame(ifstream & din);




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
//Game.cpp

#include<iostream>
#include "Game.h"

bool Game::fillGame(ifstream &din)
{
int round_Of;
ifstream din;


    din.open("file.txt");
    if(!din)
        cout << "Error: file could not be found";
    else
    {
        din >> round_Of;
        while(!din.eof())
        {
            cout  << round_Of;
            din >> round_Of;
        }
        cout << endl << endl;
        din.close();
    }

}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//main.cpp

#include "Game.h"


#include<iostream>
#include<cstring>
#include<iomanip>
#include<cctype>
#include<fstream>
#include<string>

int main()
{
    Game output;
    output.fillGame();





    return 0;
}
The error message kind of explains it all. I'm not sure how else to word it? Look at your function definitions versus how you invoke them.

I'm assuming your talking about something like this ( i had the below code before i posted) but when i do that i get the errors below the code

1
2
3
4
5
6
7
8
9
10
11
int main()
{
    Game output;
    output.fillGame(ifstream &  );





    return 0;
}


1
2
3
4
5

main.cpp:16: error: expected primary-expression before ‘)’ token
In file included from main.cpp:4:
Game.cpp:7: error: declaration of ‘std::ifstream din’ shadows a parameter
Game.cpp:7: error: aggregate ‘std::ifstream din’ has incomplete type and cannot be defined

Last edited on
You need to create stream object and pass it to Game member method and remove local one in fillGame or remove it from arguments since you are creating one in "fillGame" scope:
1
2
3
4
5
bool Game::fillGame(ifstream &din)
{
int round_Of;
ifstream din;//you got this one


Also try this instead for fail on open:
1
2
//if(!din)
if(!din.fail())


And you cannot call function like this:
 
output.fillGame(ifstream &  );


...and fillGame expects that you return bool but you didn't do that anywhere in it!
Last edited on
alright i wold have changed it but i asked and i was told that it has to be bool Game::fillGame(ifstream &din)

but i did take out the second one i had inside fillGame.

so now my problem is this

1
2
main.cpp:18: error: expected primary-expression before ‘&’ token
main.cpp:18: error: ‘din’ was not declared in this scope



this is what i changed main too

1
2
3
4
5
6
7
8
9
 


/* when i uncommet the below line if only gives the  main.cpp:18: error: expected primary-expression before ‘&’ token*/

  // ifstream din;

    Game output;
    output.fillGame(ifstream & din);



also i tried a few other things and sometimes i get an undefined reference to `Game::Game()'

on this line Game output;

which doesn't make sense( at least to me) because because isnt Game defining the reference to the object output
Topic archived. No new replies allowed.