Redefinition of class

This is a discussion on Redefinition of class within the C++ Programming forums, part of the General Programming Boards category; When I compile code from a program I'm making it give me these two errors Code: |4|error: redefinition of 'class ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    Redefinition of class

    When I compile code from a program I'm making it give me these two errors

    Code:
    |4|error: redefinition of 'class Bitmap'
    |5|error: previous definition of 'class Bitmap'
    Here is the Bitmap class
    Code:
    class Bitmap
    {
        protected:
          //Memeber variables
          HBITMAP m_hBitmap;
          int m_iWidth, m_iHeight;
    
          //Helper Methods
          void Free();
    
       public:
         //Constructor(s)/Destructor
         Bitmap();
         Bitmap(HDC hDC, LPSTR szFileName);
         Bitmap(HDC hDC, UINT uiResID, HINSTANCE hInstance);
         Bitmap(HDC hDC, int iWidth, int iHeight, COLORREF crColor = RGB(0,0,0));
         virtual ~Bitmap();
    
         //General Methods
         BOOL Create(HDC hDC, LPSTR szFileName);
         BOOL Create(HDC hDC, UINT uiResID, HINSTANCE hInstance);
         BOOL Create(HDC hDC, int iWidth, int iHeight, COLORREF crColor);
         void Draw(HDC hDC, int x, int y, BOOL bTrans = FALSE, COLORREF crTransColor = RGB(255, 0, 255));
         int GetWidth(){return m_iWidth; };
         int GetHeight(){return m_iHeight; };
    };

  2. #2
    Registered User
    Join Date
    Oct 2010
    Posts
    107
    Well, that seems valid to me. I suspect that your problem is elsewhere. What file and line did you get the error in? Please post that file instead.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    I suspect the bitmap class is in a header? If so, try adding include guards.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    107
    bijan311: Header guards, if you don't know, are preprocessor-fu for "don't double declare my stuff"

    foo.h
    Code:
    #ifndef FOO_H
    #define FOO_H
    
    // Stuff
    
    #endif

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    Know that FOO_H might not be unique enough, especially if it's a short name. It is better, then, to add something that is rather unique, namely time and date. That almost guarantees uniqueness. I make it a habit when I create include guards.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    107
    Quote Originally Posted by Elysia View Post
    Know that FOO_H might not be unique enough, especially if it's a short name. It is better, then, to add something that is rather unique, namely time and date. That almost guarantees uniqueness. I make it a habit when I create include guards.
    Lol, you really guard the hell out of your headers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

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