G
Gonzalo Aguirre
i have a classes diagram like this
------------ * ----------
| Vehicles | ------------------------- | Parking|
------------ vehicles ----------
^
|
+--+--------+
| |
-------- ---------
| Cars | | Motos |
-------- ---------
class Vehicles{
protected:
double weight;
bool stereo;
public:
Vehicles();
~Vehicles();
virtual method() = 0; /* pure cirtual method */
...
};
class Cars : public Vehicles{
private:
int doors;
public:
Cars();
~Cars();
method(); /* method redefinition */
...
};
class Motor : public Vehicles{
private:
int aThing; /* my imagination is empty */
public:
Motos();
~Motos();
method(); /* method redefinition */
...
};
class Parking{
private:
int capacity;
Vehicles *vehicles;
public:
Parking();
Parking(int);
~Parking();
void init(int, int); /* numbers of cars, number of motos */
void arrive(Vehicles &);
void leave(Vehicles &);
};
suppouse that i have to init() every day when i arrives to the parking,
and maybe some owners forget theirs cars/motos, so a should init the
parking with those numbers.
The problem is that it isn't a static number (today i have to init with 2
cars and 1 moto, and tomorrow no one forgets his/her car/moto).
So how should i create those objects??..
void
Parking::init(int c, int m){
vehicles = new Cars[c];
vehicles = new Motos[m]; // <--- IT CANNOT BE!!!..
....
}
thanks in advance
------------ * ----------
| Vehicles | ------------------------- | Parking|
------------ vehicles ----------
^
|
+--+--------+
| |
-------- ---------
| Cars | | Motos |
-------- ---------
class Vehicles{
protected:
double weight;
bool stereo;
public:
Vehicles();
~Vehicles();
virtual method() = 0; /* pure cirtual method */
...
};
class Cars : public Vehicles{
private:
int doors;
public:
Cars();
~Cars();
method(); /* method redefinition */
...
};
class Motor : public Vehicles{
private:
int aThing; /* my imagination is empty */
public:
Motos();
~Motos();
method(); /* method redefinition */
...
};
class Parking{
private:
int capacity;
Vehicles *vehicles;
public:
Parking();
Parking(int);
~Parking();
void init(int, int); /* numbers of cars, number of motos */
void arrive(Vehicles &);
void leave(Vehicles &);
};
suppouse that i have to init() every day when i arrives to the parking,
and maybe some owners forget theirs cars/motos, so a should init the
parking with those numbers.
The problem is that it isn't a static number (today i have to init with 2
cars and 1 moto, and tomorrow no one forgets his/her car/moto).
So how should i create those objects??..
void
Parking::init(int c, int m){
vehicles = new Cars[c];
vehicles = new Motos[m]; // <--- IT CANNOT BE!!!..
....
}
thanks in advance