Thread: namespace problem? maybe...

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

    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
    Location
    Waterloo, Texas
    Posts
    5,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    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, 08: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, 12:25 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM