<an****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
ive got this sample from a book i am learning from c++ , and need abit
of help on constructor
#ifndef CAR_HPP
#define CAR_HPP
class Car {
public:
Car();
Car(int initRadioFreq, int horsepower); <
// ...
protected:
bool isRunning_;
};
#endif
to me this constructor looks like the way you call a function in main..
i dont understand , can anyone help
Yes, it looks like a function call; but cannot be called like a function.
You can construct an object using that constructor like this:
Car my_car(4000, 200);
Or, you can construct an anonymous Car object as if you are calling a
function:
// A function that takes a Car
void drive(Car const &)
{
/* ... */
}
/* ... */
// Construct a temporary nameless Car and drive it:
drive(Car(5000, 150));
Ali