Cant pass ifstream

I'm trying to pass ifstream by reference to a function but it's nt working for this last one:

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
64
65
66
67
68
69
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <SFML/Graphics.hpp>

#include "PlayerStruct.h"
#include "VariableStruct.h"
#include "GameStruct.h"
#include "Prototypes.h"
#include "PlayerInputStruct.h"

using namespace std;

Game::Game(int WINDOWHEIGHT, int WINDOWWIDTH, const std::string WINDOWNAME, sf::RenderWindow& WINDOW, sf::VideoMode& VIDEOMODE): windowHeight(WINDOWHEIGHT),
                                                                                                                                 windowWidth(WINDOWWIDTH),
                                                                                                                                 windowName(WINDOWNAME),
                                                                                                                                 window(WINDOW),
                                                                                                                                 videoMode(VIDEOMODE)
{

}

GameVariables::GameVariables(string MAPNAME, string TILENAME, string LINE,
                             vector<vector<sf::Vector2i>> MAP, std::vector<sf::Vector2i> TEMPMAP,
                             sf::Texture TILETEXTURE, sf::Sprite TILES, int X, int Y, int I, int J): mapName(MAPNAME),
                                                                                                     tileName(TILENAME),
                                                                                                     line(LINE),
                                                                                                     map(MAP),
                                                                                                     tempMap(TEMPMAP),
                                                                                                     tileTexture(TILETEXTURE),
                                                                                                     tiles(TILES),
                                                                                                     x(X),
                                                                                                     y(Y),
                                                                                                     i(I),
                                                                                                     j(J)
{

}

int main()
{
    string tempMapName = "Map";
    string tempTileName = "Tiles";
    string tempLine = "temp";
    vector<vector<sf::Vector2i>> vMapTemp;
    vector<sf::Vector2i> tempTempMap;
    ifstream temp;

    int setWinHeight = 600;
    int setWinWidth = 800;
    int x;
    int y;
    int i;
    int j;
    const string setWindowName = "Window";

    sf::RenderWindow win;
    sf::VideoMode vMode;

    sf::Texture tempTexture;
    sf::Sprite tempSprite;

    Game game(setWinHeight, setWinWidth, setWindowName, win, vMode);

    GameVariables gameVariables(tempMapName, tempTileName, tempLine, vMapTemp, tempTempMap, tempTexture, tempSprite, x, y, i, j);

    MainGame(game, gameVariables, temp);
}


i get an error:

|68|undefined reference to `MainGame(Game&, GameVariables&, std::basic_ifstream<char, std::char_traits<char> >&)'|

I'm not sure what to do here.
Looks like you have not defined the MainGame function.
I have it in another .cpp file, sorry I didnt post it, I have 14 files and didnt know which one to psoit, but here is the main game function.

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
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>

#include "GameStruct.h"
#include "VariableStruct.h"
#include "Prototypes.h"
#include "PlayerInputStruct.h"

void MainGame(Game &game, GameVariables &gameVariables, std::ifstream mapList)
{

    tileMapGenerator(game, gameVariables, mapList);

    game.videoMode.height = game.windowHeight;
    game.videoMode.width = game.windowWidth;
    game.window.create(game.videoMode, game.windowName);

    while(game.window.isOpen())
    {
        sf::Event event;
        while(game.window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                {
                    game.window.close();
                }break;
                case sf::Event::Resized:
                {
                    sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                    game.window.setView(sf::View(visibleArea));
                }break;
            }
        }
        game.window.clear(sf::Color(0, 240, 255));

        drawMap(game, gameVariables, mapList);

        game.window.display();
    }
}
Nevermind I forgot the & in the main game part -_- I could have sworn I put it there.
Topic archived. No new replies allowed.