namespace problem? maybe...

This is a discussion on namespace problem? maybe... within the C++ Programming forums, part of the General Programming Boards category; I have a problem with my header Surface.h. Which is basically just a set off inline class for SDL_Surface and ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    683

    namespace problem? maybe...

    I have a problem with my header Surface.h. Which is basically just a set off inline class for SDL_Surface and limited animation. The animation is where my problem is.
    I have Graphics.h which is a simple wrapper for some SDL procedures (surface loading, blitting, and freeing).

    the line with the error is commented, and in red.
    Graphics.h - No problems with this file.
    Code:
    #pragma once
    #include <SDL.h>
    #include <SDL_TTF.h>
    
    //
    #include "ErrorValues.h"
    #include "Surface.h"
    
    namespace varia
    {
        class Graphics
        {
        public:
            Graphics();
            ~Graphics();
    
            //Initialize SDL and the display surface
            int Init(unsigned int windowWidth = 800, unsigned int windowHeight = 600, bool fullscreen = false,
                     const char* windowTitle = NULL, unsigned int bgR = 0, unsigned int bgG = 0, unsigned int bgB = 0);
    
            int createSurfaceFromFile(Surface& dst, int tran_r = -1, int tran_g = -1, int tran_b = -1);
            
            void closeSurface(Surface& src);
    
            int drawSurface(Surface& src, SDL_Rect* clip = NULL, unsigned int x_pos = 0, unsigned int y_pos = 0);
    
            int beginScene();
            int renderScene();
    
        private:
            SDL_Surface* m_screen;
    
            unsigned int m_bgR;
            unsigned int m_bgG;
            unsigned int m_bgB;
        };
    }
    Surface.h - Error in the Animation class
    Code:
    #pragma once
    //Still surface
    namespace varia
    {
        class Surface
        {
        public:
            Surface(const char* FILE):m_file(FILE),m_surface(NULL)
            {};
            ~Surface() 
            { 
                if ( m_surface != NULL )
                {
                    SDL_FreeSurface(m_surface); 
                    m_surface = NULL;
                }
            };
    
            SDL_Surface*& getSurface()
            { 
                return m_surface; 
            }
    
            const char* getFile() 
            { 
                return m_file.c_str(); 
            }
    
        protected:
            std::string m_file;
    
            SDL_Surface* m_surface;
        };
    
        class Animation : public Surface
        {
        public:
            Animation();
            ~Animation();
    
            //If clip does not exist it will create one ( or overwrite ) to the keyID provided
            void SetClip(int keyID, int x, int y, int w, int h);
    
            void Animate();
    
            int Show(varia::Graphics* graphics);//Error: 'Graphics' undeclared identifier
    
        private:
            //The Animation Timer
            Timer* m_timer;
    
            //The region vector
            std::map<int, SDL_Rect> clips;
    
            //animation vars
            int m_frame;
            int m_endFrame;
    
            float m_framesPerSecond;
        };
    }
    This makes no sense. I have Surface.h included before Graphics.h and even if i put #include "Graphics.h" in the Surface.h it won't work. I am lost for a solution.
    It will be greatly appreciated if anyone has a insight to my problem.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    the problem is Graphics.h includes Surface.h which doesn't even have a definition or declaration of Graphics. so add a forward declaration in Surface.h for that class.
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    683
    OH, lol sorry for the bother. I hate when I make those silly mistakes. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern namespace?
    By Brafil in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2009, 07:06 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Problem with atoi()?
    By ruthgrin in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2006, 11:25 AM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21