Need help with my Class??

This is a discussion on Need help with my Class?? within the Windows Programming forums, part of the Platform Specific Boards category; Hi guys, I made my first Open GL program using class and objects but i'm getting whole bunch of errors ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    26

    Need help with my Class??

    Hi guys,

    I made my first Open GL program using class and objects but i'm getting whole bunch of errors " [Linker error] undefined reference to `ClassName::MethodName(params)'

    Every time when i make new program in open GL i get big messy code of creating a window in one main class. So i decided to make a different class ".h" which creates a window and i can use it over and over again for my other programs and have less code in main class. However, the plan didn't work and i've no clue how to solve it. I've added all the libraries in projct options and required hearders within program. Please someone help, here is my code:

    Code in my class:

    Code:
     
    
    #ifndef _MAIN_H 
    #define _MAIN_H 
    
    #include <windows.h>                  // Header File For Windows 
    #include <gl\gl.h>                  // Header File For The OpenGL32 Library 
    #include <gl\glu.h>                  // Header File For The GLU32 Library 
    #include <gl\glaux.h>               // Header File For The Glaux Library 
    
    class CreateWindow 
    { 
       public: 
              GLvoid ReSizeGLScene(GLsizei width, GLsizei height); 
              int InitGL(GLvoid); 
              GLvoid KillGLWindow(GLvoid); 
              BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag); 
              LRESULT CALLBACK WndProc(   HWND hWnd, UINT uMsg, WPARAM   wParam,   LPARAM   lParam);       
    }; 
    
    
    ////////////////////////////////////// 
    //   Global Variables 
    ////////////////////////////////////// 
    extern WNDCLASS         wc;                                    // Windows Class Structure    
    extern HGLRC           hRC;                           // Permanent Rendering Context 
    extern HDC             hDC;                           // Private GDI Device Context 
    extern HWND            hWnd;                           // Holds Our Window Handle 
    extern HINSTANCE       hInstance;                            // Holds The Instance Of The Application 
    extern bool              keys[256];                              // Array Used For The Keyboard Routine 
    extern bool              active;                        // Window Active Flag Set To TRUE By Default 
    extern bool              fullscreen;                     // Fullscreen Flag Set To Fullscreen Mode By Default 
    
    #endif /*MAIN_H*/

    Code in my creatingWindow program ".cpp"
    I'm not pasting the code for all the methods/functions. I hope you guys will get the idea.

    Code:
    #include "Main.h" 
    
    GLvoid CreateWindow::ReSizeGLScene(GLsizei width, GLsizei height)      // Resize And Initialize The GL Window 
    { 
       if (height==0)                              // Prevent A Divide By Zero By 
       { 
          height=1;                              // Making Height Equal One 
       } 
    
       glViewport(0,0,width,height);                  // Reset The Current Viewport 
    
       glMatrixMode(GL_PROJECTION);                  // Select The Projection Matrix 
       glLoadIdentity();                           // Reset The Projection Matrix 
    
       // Calculate The Aspect Ratio Of The Window 
       gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); 
    
       glMatrixMode(GL_MODELVIEW);                     // Select The Modelview Matrix 
       glLoadIdentity();                           // Reset The Modelview Matrix 
    } 
    
    int CreateWindow::InitGL(GLvoid)                              // All Setup For OpenGL Goes Here 
    { 
       glShadeModel(GL_SMOOTH);                     // Enable Smooth Shading 
       glClearColor(0.0f, 0.0f, 0.0f, 0.5f);            // Black Background 
       glClearDepth(1.0f);                           // Depth Buffer Setup 
       glEnable(GL_DEPTH_TEST);                     // Enables Depth Testing 
       glDepthFunc(GL_LEQUAL);                        // The Type Of Depth Testing To Do 
       glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   // Really Nice Perspective Calculations 
       return TRUE;                              // Initialization Went OK 
    }
    Here is the code in my main program which i compile and get the errors.

    Code:
    CreateWindow objWindow; 
    
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)      // Resize And Initialize The GL Window 
    { 
            objWindow.ReSizeGLScene(width, height); 
    } 
    
    int InitGL(GLvoid)                              // All Setup For OpenGL Goes Here 
    { 
         objWindow.InitGL(); 
    } 
     
    
    
    When i compile i get following errors: 
    
    "[Linker error] undefined reference to `CreateWindowA::ReSizeGLScene(int, int)' " 
    "[Linker error] undefined reference to `CreateWindowA::InitGL()' "
    Please someone help me or guide me to solve it. I would really apperciate the help. Thank you!!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Are you including the header for your class in the main file?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 11:36 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 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