Yo,
I've been working on a clone of Breakout, and have been converting it to OOP principles. I've been inheriting from a base class, which several objects inherit from and provide their own Update function. However, whenever I seem to inherit from the class, it always gives me a parse error.
I reckon there is a syntax error with one of the functions in the base class, but when I syntax-check the file, it comes out ok. Here's the code:
BBase.h
#ifndef BASE_H
#define BASE_H
class BBase //All game objects inherit from this class
{
public:
BBase();
virtual ~BBase();
void CreateObject(float x,float y,float width,float height);
void SetObjectColor(unsigned char r,unsigned char g,unsigned char b);
virtual void Update()=0;
void Draw();
inline float GetX() {return x;}
inline float GetY() {return y;}
inline float GetR() {return r;}
inline float GetG() {return g;}
inline float GetB() {return b;}
protected:
float x,y;
float width,height;
unsigned char r,g,b;
};
#endif
BBase.cpp
#include "base.h"
BBase::BBase()
{
x=y=width=height=0;
r=g=b=255;
}
BBase::~BBase()
{
}
void BBase::CreateObject(float x,float y,float width,float height)
{
this->x=x;
this->y=y;
this->width=width;
this->height=height;
}
void BBase::SetObjectColor(unsigned char r,unsigned char g,unsigned char b)
{
this->r=r;
this->g=g;
this->b=b;
}
void BBase::Draw()
{
glPushMatrix();
glTranslatef(x,y,-25);
glColor3ub(r,g,b);
glBegin(GL_QUADS);
glVertex2f(width,0); //Top right
glVertex2f(0,0); //Top left
glVertex2f(0,height); //Bottom left
glVertex2f(width,height); //Bottom right
glEnd();
glPopMatrix();
}
And a sample object, BBall
BBall.h
#ifndef BALL_H
#define BALL_H
class BBALL : public BBase
{ //<- Parse error here
public:
BBALL();
~BBALL();
void Update();
//Accessor functions
inline float GetXDir() {return dx;}
inline float GetYDir() {return dy;}
inline void SetDelta(float dx,float dy) {this->dx=dx; this->dy=dy;}
private:
float dx,dy;
};
#endif
The headers are included like this in the main file:
#include "main.h"
#include "base.h"
#include "ball.h"
#include "bat.h"
#include "block.h"
#include "collision.h"
char cAppTitle[]="Breakout";
bool bFullscreen=true;
Any ideas as to what could be causing the problem?
[edited by - CloudNine on August 6, 2003 9:01:05 AM]