-
Problems with include
I am trying to include my class Artist , whose interface is in Artist.h, in a class called pane.
i try including the header for artist, but my code gives me an undeclared identifier. I've used the Artist before and it worked fine.
Relevant code
Code:
#ifndef _PANEH_
#define _PANEH_
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include "SDL.h"
#include "artist.h"
#include <vector>
#include "artist.h"
using std::vector;
class Pane
{
public:
void draw(Artist&); // this is where the undeclared ID comes from
};
and Artist is
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include "SDL.h"
#include "Pane.h"
class Artist
{
private:
SDL_Surface * surface;
void drawPixel(SDL_Surface*, int, int,Uint8, Uint8, Uint8);
public:
void setSurface(SDL_Surface*);
void draw();
};
-
In artist.h, draw( ) is prototyped not to accept any arguments:
In your pane class, you are attempting to pass an argument into draw();
Code:
void draw(Artist&); // this is where the undeclared ID comes from
Since there is no overloaded version of draw( ) that will accept an 'Artist' object, attempting to call draw(insert anything here) will result in a compiler issued, "undeclared Identifier" error.
-
You should use this in a single source file of your project - it's not needed in header files.
Code:
#ifdef _MSC_VER // VC++ compiler?
# pragma comment(lib, "SDL.lib")
# pragma comment(lib, "SDLmain.lib")
#endif
Also, if your header files don't have "inclusion guards", you'll want to add those as well: http://cboard.cprogramming.com/showthread.php?t=50302
If you're still having troubles, it always helps to post the compiler errors and warnings that you can't get rid of as well as the relevant code.
gg
-
You are also going to have problems because you include pane.h in artist.h and artist.h in pane.h
Unless there is more to your artist class you did not post, remove #include "pane.h"
If there is more than what youposted, be aware that 2 classes cannot mutually contain objects of each other, one class will have to settle on just pointers to the other object
-
i though having everything in #ifndef _FOO_ #endif pairs projected it from being included more then once
Yea those are reducded code version, full version is like 30 lieks for the interface didnt feel the need to post it
The Brain
I dont understand at all. thsoe are two completely seperate classes, containing two completely different draw functions.
Whats giving me trouble is this, i recently changed my draw function. i dont have the pane to actualy draw itself, i want it to use my artist class to pass information and the artist will draw it. thus i can change my artists drawing logic and not have to change my Panes.
When i try to says draw(Artist&) it says Undeclared identifier, and i dont understand why as i have included the Artist header
Darryl, i shall try using pointers. didnt know that
-
And the solution was that i have them including each other. Artist had no need for pane to be included so that cleared that up
Thanks all