Solved

Inhertiance and constructoers..

Posted on 1998-06-11
6
223 Views
Last Modified: 2010-08-05
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
Comment
Question by:yolis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:yolis
ID: 1165657
oh, all the error messages reffer to the line:
car1(char *Icolor, char *Iland, int Imaxspeed)
    : car (*Icompany_name,Imodel,Iprice,Iengine)


thanks..

0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1165658
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165659
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
Industry Leaders: 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!

 
LVL 22

Expert Comment

by:nietod
ID: 1165660
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
 
LVL 22

Expert Comment

by:nietod
ID: 1165661
Is this working for you?
0
 

Author Comment

by:yolis
ID: 1165662
ALRIGHT!
thanks a lot!!!

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question