Thread: Class declaration problems

  1. #1
    Registered User
    Join Date
    Mar 2007

    Class declaration problems

    I'm working on an .obj file loader for an opengl project I'm doing and I don't understand something that is happening. I made the class to load the object file in to certain vectors depending on the vertices, face, vertice normals, so on. But my problem comes from when I try to declare the class. I don't use any functions, all I do is declare it. I made two different projects, one an opengl and one a console so I could test it on both. For some reason it works just fine on the console program, but freezes and stops responding on the opengl project. The code for the class is kind of long so I'll just post what is needed, if anyone needs any more code just say so. And also, the two projects are using the exact same header file. Any help is appreciated!

    bool InitializeGL()
        LOADOBJ obj; //this line is the problem, i comment it out and it works fine
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  // Clear the screen to the specified color.
        // Set up the information for the first light and set it in GL_LIGHT0.
        glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
        glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
        glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
        glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 130.0f);
        glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 75.0f);
        // Enable the first light.
        // Set up the material information for our objects.
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
        glMaterialfv(GL_FRONT, GL_SPECULAR, specularLight);
        glMateriali(GL_FRONT, GL_SHININESS, 128);
        // If all went well we return true.
        return true;
    #include <iostream>
    #include "objloader.h"
    using namespace std;
    int main()
    	LOADOBJ obj; //this works without a problem, but I have no idea why
    	//if(obj.LoadObjFromFile("box.obj")) //this function also works, it's been tested
            //cout<<"Object file loaded"<<endl;
    	return 0;
    class LOADOBJ
            ObjectList *head; //head ptr in linked list of loaded object files
            int obj_load_count; //number of loaded object files
            void Destroy(); //destroys first link in the list
            ObjectList* GetNextSpace(); //get next available space in the linked list
            LOADOBJ(); //constructor
            ~LOADOBJ(); //destructor
            bool LoadObjFromFile(char*); //load object file
            int GetFileCount(); //get number of object files that have been loaded
            bool isEmpty(); //determines if the linked list is empty
            bool RenderAllObjects(); //render all the objects loaded in the linked list
    }; //end LOADOBJ class
        obj_load_count = 0; //nothing is loaded so zero
        head = NULL; //pointer points to nothing
    //almost 100&#37; sure this functions works since I tested the loading function in
    //a console window and it can correctly store all the points, faces, etc.
    ObjectList* LOADOBJ::GetNextSpace()
        if(head == NULL) return head;
            ObjectList *temp = head;
            while(temp != NULL)
                temp = temp->next;
            return temp;
    EDIT: Ok wow... I'm an idiot *SLAMS HEAD ON DESK* I was declaring the class inside the load for the opengl render. It should have been inside the main window or global. It's better now.
    Last edited by scwizzo; 12-01-2008 at 08:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. Class Declaration
    By enjoy in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2006, 10:59 AM
  3. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM