   [Solved] Problem with Header files
  Hi all! A few days ago, I started looking into C++ Header Files. They seem very useful, but since I have never used them before, I came across some stupid problems. My main one is releated to classes. Here is the code:main.cpp#include <iostream>#include <SDL.h>#include <SDL_image.h>using namespace std;#include "constants.h" //Contains constant variables#include "variables.h" //Contains variables & Surfaces#include "functions.h" //Contains functions#include "player.h" //Player class#include "gameloops.h" //Game Loops (events, logic & render)int main(int args, char *argv[]) {    SDL_Init(SDL_INIT_VIDEO);    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);    loadImages();    optimizeImages();    bool running = true;    while (running) {   events();   logic();   render();    }    cleanup();    return 0;}player.h#ifndef PLAYER_H#define PLAYER_Hclass player {    private:   int X, Y;    public:   int playerType;   double XVel, YVel;   double XPos, YPos;   void show();   void handleInput();};void player::show() {    switch (playerType) {   case 1: applySurface(X, Y, p1, screen); break;   case 2: applySurface(X, Y, p2, screen); break;    }}void player::handleInput() {    while (SDL_PollEvent(&SDLEvent) != 0) {   if (SDLEvent.type == SDL_KEYDOWN) {  switch (SDLEvent.key.keysym.sym) { case SDLK_UP: cout << "Up pressed" << endl; break; default: break;  }   }    }}#endifand variables.h#ifndef VARIABLES_H#define VARIABLES_HSDL_Surface *screen;SDL_Surface *background;SDL_Surface *p1;SDL_Surface *p2;SDL_Surface *ball;SDL_Event SDLEvent;player player1;#endifgameloops.h#ifndef GAMELOOPS_H#define GAMELOOPS_Hvoid events() {    player1.handleInput();}void logic() {}void render() {}#endiffunctions.h#ifndef FUNCTIONS_H#define FUNCTIONS_Hvoid applySurface(int X, int Y, SDL_Surface *source, SDL_Surface *destination) {    SDL_Rect offset;    offset.x = X;    offset.y = Y;    SDL_BlitSurface(source, NULL, destination, &offset);}void loadImages() {    background = IMG_Load("gfx/background.png");    //ball = IMG_Load("gfx/ball.png");    //p1 = IMG_Load("gfx/bat.png");    //p2 = IMG_Load("gfx/bat.png");}void optimizeImages() {    background = SDL_DisplayFormat(background);    //ball = SDL_DisplayFormatAlpha(ball);    //p1 = SDL_DisplayFormatAlpha(p1);    //p2 = SDL_DisplayFormatAlpha(p2);}void cleanup() {    SDL_FreeSurface(background);}#endifHowever, when I compile it at the moment, I get the error:(In variables.h): 'player' does not name a type(In gameloops.h): 'player1' was not declared in this scopeHow would I fix these errors? Sorry if I am posting so much code, however I am completley stumped here. Hope you can help me out...Thanks in advance.[Edited by - pseudobot on May 9, 2009 5:00:33 AM]
  For those two errors: variables.h needs to include player.h and gameloops.h needs include variables.h. However, these aren't the only changes need to fix your code if you want to use the headers in more than one source file. Global variables in header files need to be declared extern and non-inline function definitions need to go in source files. For more details see  this article.   ;  Thank you so much!It is working now.[smile]   