1 Attachment(s)
Inheritance problem (default constructor error)
hey guys im new here and new to programming in C++
i have this project for school and ive hit a dead end.
included i have attached the header, functions cpp, and driver cpp files
when building i get the following error :error C2512: 'automobile' : no appropriate default constructor available
now ive read the other thread in here about that same error but, the difference is that i dont have a class within a class, they are inherited classes.
any help would be extremly appreciated!!!!!!!
thx guys
Re: Inheritance problem (default constructor error)
Try to separate arguments in automobile, put them in private and rewrite automobile constructor. I think this may work out for you...
Re: Inheritance problem (default constructor error)
but i need all of the arguments in each other the classes (planes trains and automobiles) to stay in each of the respective constructors, the values come from the base class vehicles. i still dont really understand the nature of the error.
Re: Inheritance problem (default constructor error)
You've included a workspace (dsw) file but no project file (dsp). You need to post all your project's files for people to examine it properly.
Re: Inheritance problem (default constructor error)
Mind you.... one very obvious problem is that in function main() you write:-
which means you call a constructor with no parameters. However, you don't have any constructor with no parameters. Your only constructor for automobile takes 4 parameters and you must supply these whenever you instantiate an automobile object.
Re: Inheritance problem (default constructor error)
Oh - and apart from that, you've misunderstood the way that parameters are used in function calles - e.g.
Code:
automobile::automobile(double mpg, double fuelcap, int ftype, int tolls) : vehicle(mpg, fuelcap, ftype)
{
tolls = 25; // This is wrong!!
tollfees = tolls; // This is right
mpg = 20; // This is wrong!!
fuelcap = 15; // and so is this!!
ftype = 0; // and so is this!!
}
The basic idea of parameters is that they pass values into your constructor (or your function). Sometimes they can be used to return values out of a function but that wouldn't work with the type of parameter you've set up. What you did in the constructor for vehicle:-
Code:
vehicle::vehicle(double mpg, double fuelcap, int ftype)
{
milespergallon = mpg;
fuelcapacity = fuelcap;
fueltype = ftype;
// ....
}
This is the correct way to use parameters - but what you did in the constructor for automobile would achieve nothing.
Re: Inheritance problem (default constructor error)
thank u so much john e i will edit my code and update with the results. i apreciate the help alot man! im so used to vb which was pretty straight forward with functions and passing arguments.