#include <iostream>
class Car{
public:
Car(float newSpeed = 0, double newHP = 100);
protected:
double HP;
private:
float speed;
};
Car::Car(float newSpeed, double newHP)
{
speed = newSpeed;
HP = newHP;
}
#include <vector>
using namespace std;
int main(){
Car car(10, 100);
return(0);
}
The above code does not compile with an error saying: “1>c:\users\aaron\documents\visual studio 2010\projects\ass3\ass3\main.cpp(9): error C2661: ‘Car::Car’ : no overloaded function takes 2 arguments”
I am not sure why. I first tried this with default arguments to the Car constructor
Car::Car(float newSpeed = 0, double newHP = 100);
but that did not work either.
I have been working on this for 3 days now. any help is much appreciated.
Thank you.
Edit: suggestions below
(Wild guess warning)
Based on all your descriptions in the comments, this looks like a situation where you have another car.h file somewhere on your computer. And the compiler is finding that one.
Since you’re in Windows, it may also be Car.h or CAR.H, etc.
Edit
With no clear resolution, “I am going to call this solved. Thank you for all your help. – ngong0”.
Voting to close.