Accessing class from different file?

So, I am trying to access and use a class that is in a different file to avoid too much clutter in one file. However, my code keeps getting the following error in Codeblocks: error: no match for call to '(World1) (SDL_Renderer*&, SDL_Texture*&, SDL_Joystick*&)'

Relevant code is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//game.h
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED

#include <SDL.h> //for SDL 2.0.5
#include <SDL_image.h> //for SDL_image 2.0.1
#include <stdio.h>
#include <iostream>

#include "worlds.h"

using namespace std;

//unrelated code
#endif // GAME_H_INCLUDED 


1
2
3
4
5
//game.cpp
//lots of code above
World1 world;
world (renderer, texture, gameController);
//lots of code below 


1
2
3
4
5
6
7
8
9
//worlds.h
class World1
{
    public:
        world1(SDL_Renderer*&, SDL_Texture*&, SDL_Joystick*&); // constructor
        void loadPlayer(SDL_Renderer*&, SDL_Texture*&, SDL_Joystick*&); //loads player
};



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "game.h"
#include "worlds.h"

//World 1
//constructor
World1::world1(SDL_Renderer*& renderer, SDL_Texture*& texture, SDL_Joystick*& gameController)
{
    World1::loadPlayer(renderer, texture, gameController);
}

void World1::loadPlayer(SDL_Renderer*& renderer, SDL_Texture*& texture, SDL_Joystick*& gameController)
{
    texture = IMG_LoadTexture(renderer, "male_base-test-anim.gif");

    if (texture == 0)
    {
        cout << "Unable to load texture.";
    }
}

//End world 1


Is there something wrong with my class declaration?
Last edited on
is there by chance # includes in your .cpp files that are needed but "unseen at this point in the compiling process" when you only include the .h files? Looking only at the libraries that it is mad about?

I don't see anything else yet.
Are you saying to include the libraries? I have those in the "game.h" file. I would think that the opposite would be true, where I need to include them less. However, the guard words should stop anything from happening if I include things too much, I would think.

Edit: It seemed to work when I just used a default constructor.
Last edited on
Topic archived. No new replies allowed.