anddos@gmail.com wrote:[color=blue]
> 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();[/color]
This is a default constructor, meaning that no parameters need to be
supplied to it. Usually such a constructor will initialize data members with
default values.
[color=blue]
> Car(int initRadioFreq, int horsepower); <[/color]
This is a constructor that will use the passed parameters to initialize the
object.
[color=blue]
> // ...
> protected:
> bool isRunning_;
>
> };
> #endif
>
> to me this constructor looks like the way you call a function in
> main.. i dont understand , can anyone help[/color]
You can use either constructor to create an object, e.g.,
Car car1; // uses default constructor;
Car car2(1500, 10000); // uses other constructor
A class can have any number of constructors that have different numbers and
types of parameters. The creator of the object chooses the appropriate one
for his purpose.
DW