Solved

Inhertiance and constructoers..

Posted on 1998-06-11
6
220 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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

770 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