Hallo all,
I have a question for implementing Inheritance in C++. I think I miss the concept of inheritance C++ somehow, because the second class can not take the parameter from the first class..
I need to use a class Carbol and Carbol2. In Carbol2, I need to add a particular extra function, and the rest is taking the parameters and methods from Carbol
for Class Carbol, this is I am going to make
class Carbol
{
public:
float radius,dtof,color,lofs;
Carbol(float r,float df,char c,float ls)
{
radius=r;
dtof=df;
color=c;
lofs=ls;
}
void draw(Carbol a)
{
the function that I want to implement with parameter passing
}
};
and for the second class
class Carbol2:public Carbol
{
void gambar(Carbol2)
{
another extra function that I want to add
}
};
and in int main
Carbol object(0.7,0,'y',1);
object.draw(object);
Carbol2 ubjuct;
ubjuct.gambar(0.6,2,'g',3); // this object should take the function from carbol, and add another function from carbol2
and the error when I compile this is
error: no matching function for call to ‘Carbol::Carbol()
I think the problem is that I made a wrong implementation of Carbol2 (but I tried to make a lot of changes in the source code, it failed somehow).. From the error, it is said no matching function to call the first class, so does it mean that I have to change the structure for the first class? But if I don't use the second class, and only implement Carbol object(0.7,0,'y',1); object.draw(object); in int main, it worked just fine.. Can anyone point out what mistake I have in this general concept? I apologize if you guys having a difficulty in understanding my English, but I hope you could get the general idea about the difficulty I am having..
Cheerz,
Reza