T
TBass
Hello. I'm trying to make an abstract class, but when I declare one of
the derived classes, I get the error "cannot instantiate abstract
class". Can anyone tell me what I'm doing wrong?
ABSTRACT CLASS:
class CDCtrl
{
protected:
CDCtrl(CDCtrl &c);
public:
CDCtrl( void );
virtual ~CDCtrl( void );
/* Control Unique ID */
unsigned int UID;
/* LOCATION ON THE PALLATE */
double X;
double Y;
double CX;
double CY;
/* APPEARANCE */
unsigned int ForeColor;
unsigned int BackColor;
bool Visible;
void Opacity(double Opacity);
double Opacity(void);
virtual bool InRect(double x, double y) const = 0;
virtual bool OnLButtonDown(double x, double y) = 0;
virtual bool OnLButtonUp(double x, double y) = 0;
virtual bool OnRButtonDown(double x, double y) = 0;
virtual bool OnRButtonUp(double x, double y) = 0;
virtual bool OnMouseMove(double x, double y, bool button_flag)
= 0;
virtual bool OnKeyDown( unsigned int VKeyCode, unsigned int ModKeys )
= 0;
virtual void Draw( DPalette &refPalette );
protected:
double m_opacity;
}; /* Class CDCtrl */
/*
* DCtrl.c
* The Daedalus control base classes and templates.
*/
#include ".\DCtrl.h"
/*
* CONSTRUCTOR
*/
CDCtrl::CDCtrl( void ) :
X(0),
Y(0),
CX(0),
CY(0),
UID(0),
ForeColor(0x000000),
BackColor(0xFFFFFF),
Visible(true),
m_opacity(1)
{
} /* CDCtrl::CDCtrl */
/*
* DESTRUCTOR
*/
CDCtrl::~CDCtrl( void )
{
} /* CDCtrl::CDCtrl */
/*
* CDCtrl::Opacity
*/
void
CDCtrl::Opacity( double Opacity )
{
if ( Opacity < 0 )
{
m_opacity = 0;
}
else if ( Opacity > 1 )
{
m_opacity = 1;
}
else
{
m_opacity = Opacity;
}
} /* CDCtrl::Opacity */
/*
* CDCtrl::Opacity
*/
double
CDCtrl::Opacity(void)
{
return m_opacity;
}
DERIVED CLASS:
class CDCtrl_Button : public CDCtrl
{
public:
CDCtrl_Button(void);
~CDCtrl_Button(void);
int Value() const { return m_value & 0x01; }
void Value(int value);
/*
virtual bool InRect(double x, double y);
virtual bool OnLButtonDown(double x, double y);
virtual bool OnLButtonUp(double x, double y);
virtual bool OnRButtonDown(double x, double y);
virtual bool OnRButtonUp(double x, double y);
virtual bool OnMouseMove(double x, double y, bool
button_flag);
virtual bool OnKeyDown( unsigned int VKeyCode, unsigned int
ModKeys );
*/
virtual void Draw( DPalette &refPalette );
private:
int m_value;
bool m_mouse_move;
};
/*
* CONSTRUCTOR
*/
CDCtrl_Button::CDCtrl_Button(void) :
CDCtrl(),
m_value(0),
m_mouse_move(0)
{
}
/*
* DESTRUCTOR
*/
CDCtrl_Button::~CDCtrl_Button(void)
{
}
/*
* CDCtrl_Button::draw
* Render the control on to the pallete.
*/
void
CDCtrl_Button:raw( DPalette &refPalette )
{
refPalette.roundedRect( X, Y, CX, CY, 2, 2, 2, 2 );
}
FROM THE MAIN PROGRAM:
CDCtrl_Button m_button;
This is my first abstract class. Can anyone tell me what I'm doing
wrong?
Thanks in advance,
TBJ
the derived classes, I get the error "cannot instantiate abstract
class". Can anyone tell me what I'm doing wrong?
ABSTRACT CLASS:
class CDCtrl
{
protected:
CDCtrl(CDCtrl &c);
public:
CDCtrl( void );
virtual ~CDCtrl( void );
/* Control Unique ID */
unsigned int UID;
/* LOCATION ON THE PALLATE */
double X;
double Y;
double CX;
double CY;
/* APPEARANCE */
unsigned int ForeColor;
unsigned int BackColor;
bool Visible;
void Opacity(double Opacity);
double Opacity(void);
virtual bool InRect(double x, double y) const = 0;
virtual bool OnLButtonDown(double x, double y) = 0;
virtual bool OnLButtonUp(double x, double y) = 0;
virtual bool OnRButtonDown(double x, double y) = 0;
virtual bool OnRButtonUp(double x, double y) = 0;
virtual bool OnMouseMove(double x, double y, bool button_flag)
= 0;
virtual bool OnKeyDown( unsigned int VKeyCode, unsigned int ModKeys )
= 0;
virtual void Draw( DPalette &refPalette );
protected:
double m_opacity;
}; /* Class CDCtrl */
/*
* DCtrl.c
* The Daedalus control base classes and templates.
*/
#include ".\DCtrl.h"
/*
* CONSTRUCTOR
*/
CDCtrl::CDCtrl( void ) :
X(0),
Y(0),
CX(0),
CY(0),
UID(0),
ForeColor(0x000000),
BackColor(0xFFFFFF),
Visible(true),
m_opacity(1)
{
} /* CDCtrl::CDCtrl */
/*
* DESTRUCTOR
*/
CDCtrl::~CDCtrl( void )
{
} /* CDCtrl::CDCtrl */
/*
* CDCtrl::Opacity
*/
void
CDCtrl::Opacity( double Opacity )
{
if ( Opacity < 0 )
{
m_opacity = 0;
}
else if ( Opacity > 1 )
{
m_opacity = 1;
}
else
{
m_opacity = Opacity;
}
} /* CDCtrl::Opacity */
/*
* CDCtrl::Opacity
*/
double
CDCtrl::Opacity(void)
{
return m_opacity;
}
DERIVED CLASS:
class CDCtrl_Button : public CDCtrl
{
public:
CDCtrl_Button(void);
~CDCtrl_Button(void);
int Value() const { return m_value & 0x01; }
void Value(int value);
/*
virtual bool InRect(double x, double y);
virtual bool OnLButtonDown(double x, double y);
virtual bool OnLButtonUp(double x, double y);
virtual bool OnRButtonDown(double x, double y);
virtual bool OnRButtonUp(double x, double y);
virtual bool OnMouseMove(double x, double y, bool
button_flag);
virtual bool OnKeyDown( unsigned int VKeyCode, unsigned int
ModKeys );
*/
virtual void Draw( DPalette &refPalette );
private:
int m_value;
bool m_mouse_move;
};
/*
* CONSTRUCTOR
*/
CDCtrl_Button::CDCtrl_Button(void) :
CDCtrl(),
m_value(0),
m_mouse_move(0)
{
}
/*
* DESTRUCTOR
*/
CDCtrl_Button::~CDCtrl_Button(void)
{
}
/*
* CDCtrl_Button::draw
* Render the control on to the pallete.
*/
void
CDCtrl_Button:raw( DPalette &refPalette )
{
refPalette.roundedRect( X, Y, CX, CY, 2, 2, 2, 2 );
}
FROM THE MAIN PROGRAM:
CDCtrl_Button m_button;
This is my first abstract class. Can anyone tell me what I'm doing
wrong?
Thanks in advance,
TBJ