#include <iostream>
#include "Car.h";
usingnamespace std;
Car::Car(){
cout<<"Car's defautlt constructor called"<< endl;
}
Car::Car(double d){
cout<<"Car("<<d <<") constuctor called"<< endl;
}
Car::~Car(){
cout<<"Car's destructor called"<<endl;
}
int main()
{
//why doesn't the next line seem to do anything
Car c();
//this next line works fine
Car c2(1.2);
return 0;
}
my Car header file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED
class Car{
public:
Car ();
Car (double m);
~Car();
private:
double mpg;
};
#endif // CAR_H_INCLUDED
It is because Car c(); looks like a prototype for a function named 'c', taking no arguments, that returns a 'Car'. Hence, that's what the compiler thinks it is.