Ivor Horton cites this example in his section on Inheiritance (Beginning VC++ 6.0)
// Listing 8_01-01
class Box
{
public:
double length;
double breadth;
double height;
Box(double lv=1.0, double bv=1.0, double hv=1.0)
{
length = lv;
breadth = bv;
height = hv;
}
};
// Listing 8_01-02
class CandyBox: Box
{
public:
char* contents;
CandyBox(char* str= "Candy") // Constructor
{
contents = new char[ strlen(str) + 1 ];
strcpy(contents, str);
}
~CandyBox() // Destructor
{ delete[] contents; };
};
I understood the syntax and procedure going on so I wrote some code just to reinforce what I knew.
My code:
class CBase{
public:
CBase(int one,int two,int three);
~CBase();
// example member variables
int m_one;
int m_two;
int m_three;
};
class CSpecial:CBase{
public:
CSpecial(int one,int two,int three,int four);
~CSpecial();
m_four;
private:
bool hasNumber(int num);
};
CBase::CBase(int one,int two,int three){
int m_one=one;
int m_two=two;
int m_three=three;
cout << "Object Created" << endl;
};
CBase::~CBase(){
cout << "Object Deleted" << endl;
};
CSpecial::CSpecial(int one,int two,int three,int four){
int m_one=one;
int m_two=two;
int m_three=three;
int m_four=four;
cout << "Object Created" << endl;
};
CSpecial::~CSpecial(){
cout << "Object Deleted" << endl;
};
When I compile this I recieve an error saying there is no default constructor for CBase and the error tag points to CSpecial''s constructor. What''s is different from Horton''s example?