Damn error message!!! C++ - Need help

Associate
Joined
26 Jun 2003
Posts
1,140
Location
North West
Im trying to compile my program and I have no idea what is causing this error.

I have a class "Button" with a constructor:

Button::Button(void)
{
// Stuff
}

In another class called "Interface" I include the above file and create 4 buttons using:

Button button1;
Button button2;
Button button3;
Button button4;

Im getting this error when compiling:

error: 'Button' is used as a type, but is not defined

What can be causing this error?

THx
 
Last edited:
JonD said:
Im trying to compile my program and I have no idea what is causing this error.

I have a class "Button" with a constructor:

Button::Button(void)
{
// Stuff
}

In another class called "Interface" I include the above file and create 4 buttons using:

Button button1;
Button button2;
Button button3;
Button button4;

Im getting this error when compiling:

error: 'Button' is used as a type, but is not defined

What can be causing this error?

THx


A class definition is basically a list of the attributes, metrhods and member data that defines what the class is. All you have there is a definition of what the constructor looks like.

The header file should look like this

#ifndef BUTTON_H_DEFINED
#define BUTTON_H_DEFINED

//...any #includes that your class needs
// any forwrad declarations

class Button
{
public:

//public methods and atributes

protected:

//protected methods and attributes

private:

//private methods and attributes
};

//any inline functions that are members of Button should go here....
 
Button.cpp: (in dir: "src/button.cpp")

#include "../include/button.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Button::Button(void) { }

Button::~Button(void) { }


-------------------------------


Button.h: ("include/button.h")

#ifndef _BUTTONH_
#define _BUTTONH_

#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

class Button
{

private:

int id;
int x;
int y;
char* string;

public:

Button(void);
~Button(void);

};

#endif
 
Tkink I fixed it.

On my main.h file I had a copy and paste noob error. I had done #define _BUTTONH_ on that so the header file for the Button class was not compiling. NOOB!!!! lol

Although I am now gettin these types of errors:

/usr/X11R6/lib/libGL.a(glxext.o)(.text+0x1f): In function `__glXGetCurrentContext':
: undefined reference to `pthread_key_create'
/usr/X11R6/lib/libGL.a(glxext.o)(.text+0x3e): In function `__glXGetCurrentContext':
: undefined reference to `pthread_getspecific'
/usr/X11R6/lib/libGL.a(glxext.o)(.text+0x6f): In function `__glXSetCurrentContext':
: undefined reference to `pthread_setspecific'
/usr/X11R6/lib/libGL.a(glxext.o)(.text+0x87): In function `__glXSetCurrentContext':

Am i not including something?

---- FIXED ----

The above was due to me using an out of data Makefile.

Thx anyway

JD
 
Last edited:
JonD said:
Button.cpp: (in dir: "src/button.cpp")

#include "../include/button.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Button::Button(void) { }

Button::~Button(void) { }


-------------------------------


Button.h: ("include/button.h")

#ifndef _BUTTONH_
#define _BUTTONH_

#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

class Button
{

private:

int id;
int x;
int y;
char* string;

public:

Button(void);
~Button(void);

};

#endif

FYI those header files are deprecated - you should be using cstdio, cstdlib and cmath. Also there's no need to use an explicit void in functions that take no parameters.
 
Back
Top Bottom