• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Inhertiance and constructoers..

when i try to run this code:
#include <iostream.h>
#include <string.h>

class car{
char company_name[10];
int model,engine;
long price;
public:
car(char *Icompany_name,int Imodel,long Iprice,int Iengine)
{
  strcpy(company_name,Icompany_name);
  model=Imodel;
  price=Iprice;
  engine=Iengine;
}
void show()
{
  cout<<"Showing paramaters of class car\n"
  "Company name: "<<company_name<<
  "\nModel number: "<<model<<
  "\nPrice: "<<price<<
  "\nEngine capacity: "<<engine<<'\n';
}
int get_model() { return(model); }
int get_price() { return(price); }
int get_engine() { return(engine); }
char *get_company_name() { return(company_name); }
};

class car1:public car{
char color[10],land[20];
int maxspeed;
public:
car1(char *Icolor, char *Iland, int Imaxspeed)
: car (*Icompany_name,Imodel,Iprice,Iengine)
{
  strcpy(color,Icolor);
  strcpy(land,Iland);
  maxspeed=Imaxspeed;
}
void show()
{
  cout<<"Showing paramaters of class car\n"
  "Company name: "<<get_company_name()<<
  "\nModel number: "<<get_model()<<
  "\nPrice: "<<get_price()<<
  "\nEngine capacity: "<<get_engine()<<
  "\nColor: "<<color<<
  "\nLand: "<<land<<
  "\nMaxSpeed: "<<maxspeed<<'\n';
}
};


main()
{
  car bla("Yoli co.",554,10100,800);
  bla.show();
  return 0;
}

it gives me this error messages:
'Undefined symbol 'Icompany_name'
'Undefined symbol 'Imodel'
'Undefined symbol 'Iprice'
'Undefined symbol 'Iengine'
'Could not find a match for 'car::car(undefined,undefined,undefined,undefined)'
0
yolis
Asked:
yolis
  • 4
  • 2
1 Solution
 
yolisAuthor Commented:
oh, all the error messages reffer to the line:
car1(char *Icolor, char *Iland, int Imaxspeed)
    : car (*Icompany_name,Imodel,Iprice,Iengine)


thanks..

0
 
nietodCommented:
answer coming.
0
 
nietodCommented:
in the 2nd line of

car1(char *Icolor, char *Iland, int Imaxspeed)
   : car (*Icompany_name,Imodel,Iprice,Iengine)

you are trying to construct the "car" portion of a car1 object.  to do this you must pass the information that the car constructor need, like the company name, model, price, and engine.  However, you don't have that information to pass.  You pass lcompany_name for the company name, but you don't have lcompany_name defined.  Same with the others.  Does that make sense?  One way to make this work is to pass the company name and other information to the car1 constructor, like

car1(char *Icompany_name,int Imodel,long Iprice,int Iengine,char *Icolor, char *Iland, int Imaxspeed)
   : car (*Icompany_name,Imodel,Iprice,Iengine)
{
     strcpy(color,Icolor);
     strcpy(land,Iland);
     maxspeed=Imaxspeed;
   }

Now when you construct a "car1", you have to specify the 5 parameters that a "car" requires as well as the 4 extra parameters that a "car1" requires.  Does that make sense?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nietodCommented:
By the way, another solution would be to create a default constructor for the car class.  Then car1 could leave the car information default constructred.  This might or might not be a useful solution for you, I can't tell from what I've seen.
0
 
nietodCommented:
Is this working for you?
0
 
yolisAuthor Commented:
ALRIGHT!
thanks a lot!!!

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now