undefined reference error


i keep getting this error in my main.cpp

main.cpp:17: undefined reference to `Game::Game()'

this is the code i have pertaining to the error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "Game.h"
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cctype>
#include<fstream>
#include<string>

int main()
{
    ifstream din;

    Game output;
    output.fillGame(din);





    return 0;
}


i doubt it but just in case here is the game.cpp file
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
#include<iostream>
#include "Game.h"
#include<fstream>
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();
    }
    return true;
}



and .h file. there is other stuff but i didn't include it because it doesn't go with this question

1
2
3
4
5
6
7
8
9
class Game
{
public:
  

    bool fillGame(ifstream & din);
   

};
Can we see the rest of "Game.h". The error means that the compiler can't find the default constructor Game::Game(), which is implicitly called here:
Game output;

I'm guessing you defined a custom constructor, so that the default one is no longer generated, in which case you would have to add it yourself. To be sure, I would need to see your full "Game.H" file.

I hope this helps.
i think your asking about this part inside game.h file


what i mean is i have the default constructor and im asking about the non default

1
2
3
4
5
6
7
8



// default constructor
    //Game();

    // non-default constructor why is this needed?
    //Game(); 
Last edited on
Those two prototypes are the same. They are both the default constructor. You can of course only have one, as you can't have to functions with the same name and parameter list. Is there any particular reason why it is all commented out?
because when i was typing the second one an error came up so i just commented it out before i copied and pasted, but other than that i have the first on although i think i need to add some stuff to the constructor like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Game
{
public:
    //  constructor
   Game() 
{ /*
//some code but im not entirely sure what but from googling and reading i think im on the right path?
*/ }


  // destrucor
   ~Game() 

};


Topic archived. No new replies allowed.