Solved

Inhertiance and constructoers..

Posted on 1998-06-11
6
218 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
Comment Utility
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
Comment Utility
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
Is this working for you?
0
 

Author Comment

by:yolis
Comment Utility
ALRIGHT!
thanks a lot!!!

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now