Class Object Declaration

Can anyone tell what is wrong with the code I wrote. I am trying to create an object with the class but it won't let me.

The error is as follows:
||=== Build: Debug in Lab 9-3 (compiler: GNU GCC Compiler) ===|
main.cpp||In function 'int main()':|
main.cpp|51|error: no matching function for call to 'Car::Car()'|
main.cpp|51|note: candidates are:|
main.cpp|20|note: Car::Car(int, std::string)|
main.cpp|20|note: candidate expects 2 arguments, 0 provided|
main.cpp|6|note: Car::Car(const Car&)|
main.cpp|6|note: candidate expects 1 argument, 0 provided|
main.cpp|6|note: Car::Car(Car&&)|
main.cpp|6|note: candidate expects 1 argument, 0 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

This is my code:


#include <iostream>
#include <string>

using namespace std;

class Car
{
private:
int yearModel;
string make;
int speed;
public:
Car(int, string);
int getYear() const;
string getMake() const;
int getSpeed() const;
int accelerate(int);
int brake(int);
};
Car::Car(int model, string makeofcar)
{
yearModel = model;
make = makeofcar;
speed = 0;
}
int Car::getYear() const
{
return yearModel;
}
string Car::getMake() const
{
return make;
}
int Car::getSpeed() const
{
return speed;
}
int Car::accelerate(int carspeed)
{
carspeed = carspeed + 5;
return carspeed;
}
int Car::brake(int carspeed)
{
carspeed = carspeed - 5;
return carspeed;
}

int main()
{
Car car1;
cout << "Hello world!" << endl;
return 0;
}
Car(int, string);
A car is constructed by giving 2 parameters: the model and the make (¿?).
By instance Car foo(42, "");

You did Car car1; providing 0 parameters, ¿what did you expect?
Oh ok. Gotcha :) Thanks a lot.
Topic archived. No new replies allowed.