Class Constructor Overload not working

#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

Answers


(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.


if this is your ctor

Car();

then you will not succeed with giving two arguments

you need to create a constructor that takes two arguments

class Car{ public: Car(int HP, float speed);


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.