1

I'm using Code::Blocks to make a simple game. I'm trying to learn how to keep good file structure, but I'm clearly missing something because I can't seem to call a program-scope function from an object that is defined in a .cpp file.

So, I have an object, tank, which is declared in a header file, include/tank.h, and which is defined in a .cpp file, src/tank.cpp (these are the files that Code::Blocks made for me when I used the file->new->class menu). I also have a header file for the function apply_image(), called apply.h. apply.h is included in the main.cpp file.

When src/tank.cpp looks like this:

#include "tank.h"

void tank::drawMe(SDL_Surface* screen)
{
    apply_surface(x,y, tankImg, screen);
}

I get a compiler error that reads |error: ‘apply_surface’ was not declared in this scope| So I add an #include for "apply.h", like so:

#include "tank.h"
#include "apply.h"

void tank::drawMe(SDL_Surface* screen)
{
    apply_surface(x,y, tankImg, screen);
}

and now I get a compiler error that reads |multiple definition of `apply_surface(int, int, SDL_Surface*, SDL_Surface*)'| I can't win!

I've consulted a few texts on C++, but I can't see what I'm doing differently. Any clarification is appreciated, thanks!

Max
  • 41
  • 5
  • Try looking at [this](http://stackoverflow.com/questions/12323290/c-multiple-definitions) – CoffeeRain Nov 01 '12 at 00:44
  • thanks! I added `extern void apply_surface(int, int, SDL_Surface*, SDL_Surface*);` to my first code snippet and it works fine! Thank you very much! – Max Nov 05 '12 at 01:53

0 Answers0