I'm trying to use inheritance now to make things much more organised. I have a superclass of type item and an inheriting class of type special_item.
The book I'm reading an example from has something like this
Code:
class object
{
object(void){...}
};
class object2: public object
{
object2(void){...} //overrides default constructor
object2(parameters){...} //overloads a constructor that was not present
};
So in my test, I did something similar, except that I left the parameters for the second constructor (that is, the one it says is overloading the constructor) to be void. The compiler doesn't like that, as it looks just like the one immediately preceeding it.
So what's the deal? If you want to override the constructor with a new one do you have to have different parameters? What if I want it to be void in both? Should I just give it a parameter that defaults to NULL and ignore it?
Here is my code, if it matters.
Code:
class item
{
public:
string name, desc;
unsigned short int id;
friend bool operator==(const item& lhs, const item& rhs){return (lhs.id==rhs.id);}
item(void)
{
id = item_id++; name = "test"; desc = "a test object";
}
};
class special_item: public item
{
public:
special_item(void){}
special_item(void)
{
id = item_id++; name = "special"; desc = "special, one of a kind object";
}
};
(edit)
I realise that, in this specific instance, it doesn't make a difference whether the parent class' constructor is called; but this is just a test program for learning, and I'd like to figure it out anyway.