Thread: Problems with include

  1. #1
    Wen Resu
    Join Date
    May 2003
    Posts
    219

    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();
    
    };

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    In artist.h, draw( ) is prototyped not to accept any arguments:
    Code:
    void draw();

    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.
    Last edited by The Brain; 06-07-2005 at 01:42 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    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

  4. #4
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    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

  5. #5
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    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

  6. #6
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programing doubt
    By sivasankari in forum C Programming
    Replies: 2
    Last Post: 04-29-2008, 09:19 AM
  2. some problems with #include
    By Cmaniac in forum C Programming
    Replies: 6
    Last Post: 04-15-2007, 11:28 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. #Include "class" problems
    By Unregistered in forum C++ Programming
    Replies: 17
    Last Post: 11-26-2001, 10:40 AM