Trouble With Class in Custom Framework

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
This is going to be a hard problem to describe so please bear with me as I try to explain all of it.

I've begun work on my own GUI framework for my projects. My framework is called SimGUI and has in it a file SimGUI.h which simply includes all the other files. The one of interest is SimGUIFrame.h which declares the class SimGUIFrame. My framework compiles just fine without even a warning.

Now I go to my test app and include <SimGUI/SimGUI.h> which works just fine, but when I try to declare an instance of SimGUIFrame, I get an error stating that SimGUIFrame is used as a type but not declared as such.

Any idea why my program can't find the class I declared in the framework? Let me know if you need more information to go off of to help because this is quite an elaborate problem that I wasn't sure how to exactly ask the question.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
I think you should post SimGUI.h, SimGUIFrame.h and the source file that's using it.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #3
New code three posts down. Just saving space.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #4
This also raises another question: can a class have a pointer to an instance of iteself such as:
Code:
class aClass
{
public:
    aClass();
   ~aClass();
private:
   aClass *next;
};
Quote this message in a reply
Member
Posts: 131
Joined: 2004.10
Post: #5
Quote:This also raises another question: can a class have a pointer to an instance of iteself
Yes, but you might consider using a premade container found in STL (or similar) rather than doing the linked list (or dynamic array or whatever you end up choosing to use) coding yourself.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #6
More updates (because this is all I've been working on):

I've removed the files from the framework and just added them to my project (to see if that helps) and it still won't recognize the class as a type. It will, however, recognize SimGUIEntity. It also won't recognize SimGUITest (another class in that group). I'm wondering what would cause Xcode to not see any class besides SimGUIEntity.h when I include SimGUI.h.

Here's all the relevent code:
SimGUI.h
Code:
#ifndef __SIMGUI_H__
#define __SIMGUI_H__

#include "SimGUIEntity.h"
#include "SimGUIFrame.h"
#include "SimGUITest.h"

#endif
SimGUIEntity.h
Code:
#ifndef __SIMGUIENTITY_H__
#define __SIMGUIENTITY_H__

enum SimGUIType
{
    SimGUIUnknown,
    SimGUIFrame,
    SimGUILabel,
    SimGUIButton,
    SimGUITextField,
    SimGUISlider
};

class SimGUIEntity
{
public:
    SimGUIEntity();
    SimGUIEntity(SimGUIType t);
    virtual ~SimGUIEntity();
    
    virtual void Draw()    const = 0;
    
    SimGUIType        type;
    bool            visible;
    SimGUIEntity    *next;
};

#endif
SimGUIFrame.h
Code:
#ifndef __SIMGUIFRAME_H__
#define __SIMGUIFRAME_H__

#include "SimGUIEntity.h"
#include "SimEngineStructs.h"
#include "SimEngineStructFunctions.h"
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>

class SimGUIFrame
{
public:
    SimGUIFrame();
    SimGUIFrame(SimPoint2D pos, SimColor c = SimMakeColor(SimColorBlack,0));
    SimGUIFrame(SimSize2D size, SimColor c = SimMakeColor(SimColorBlack,0));
    SimGUIFrame(SimPoint2D pos, SimSize2D size, SimColor c = SimMakeColor(SimColorBlack,0));
    SimGUIFrame(SimRect2D rect, SimColor c = SimMakeColor(SimColorBlack,0));
    virtual ~SimGUIFrame();
    
    void AddEntity(SimGUIEntity    *entity);
    void Draw();    
    
protected:
    bool            visible;
    SimRect2D        frame;
    SimColor        color;
    SimGUIEntity    *firstObject;
};

#endif
main.h
Code:
#ifndef __MAIN_H
#define __MAIN_H

#define FULLSCREEN_ON    0
#define VSYNC_ON        1

//system includes
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include "SimEngineStructs.h"
#include "SimEngineStructFunctions.h"
#include "SimGUI.h"
...
(function declarations)
main.cpp
Code:
#include "main.h"

//external variables from init.cpp
extern bool done;
extern bool escPressed;
extern bool wPressed,sPressed,aPressed,dPressed,qPressed,ePressed,leftMousePressed,rightMous​ePressed,rightMouseHeld;
extern int screenWidth, screenHeight, lastFramesPerSecond;
extern float frameInterval;

GlyphToolkit *font1 = NULL;

SimGUIFrame    window;
Code:
Errors:
main.cpp:12: error: 'SimGUIFrame' is used as a type, but is not defined as a type.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #7
Zekaric Wrote:Yes, but you might consider using a premade container found in STL (or similar) rather than doing the linked list (or dynamic array or whatever you end up choosing to use) coding yourself.
I may later but first I must figure out why this darn thing won't recognize my class as a type. Then I'll look into handling the data. I was thinking about using a premade container but I think my design will work fine. There's no way to remove items, but being a GUI I don't really think I need that feature. I do have a boolean value to determine whether or not to draw a certain thing so I can alter the GUI at runtime in that respect. I also don't need sorting or anything.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
I can't see what's going on there... You may need to preprocess main.cpp to get a handle on what the compiler's seeing.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #9
OneSadCookie Wrote:I can't see what's going on there... You may need to preprocess main.cpp to get a handle on what the compiler's seeing.
How do I do that?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble with UIImage in a class Jmcclane 8 4,492 Sep 10, 2010 01:24 PM
Last Post: Jmcclane
  Objective-C: drawing a custom class to a custom view GryphonClaw 1 4,148 Dec 10, 2004 03:32 AM
Last Post: GryphonClaw