Hey guys I've been asked to create an array of objects on the heap for my assignment but I cant seem to find any examples that explain it well enough on the web.
So what I got is:
//Heabder File
class Wheel{
public:
Wheel() : pressure(32) {
ptrSize = new int(30);
}
Wheel(int s, int p) : pressure(p) {
ptrSize = new int(s);
}
~Wheel() { delete ptrSize; }
void pump(int amount) {
pressure += amount;
}
private:
int *ptrSize;
int pressure;
};
Ok so thats the wheel class and I have to coppy the objects into my "RacingCar" class through an Array on the heap.
class RacingCar{
public:
RacingCar() {
speed = 0;
acceleration = 0;
direction = 0;
}
// Modifiers
//---------------------------------------------
void accelerate() {
speed = speed + acceleration;
}
void setSpeed(int s) {
acceleration = s;
}
void brake(int braking) {
speed = speed - braking;
}
void turn(int newDirection) {
direction = direction + newDirection;
}
//Return Variables
//---------------------------------------------
int getSpeed() { return speed; }
int getDirection() {
if (direction > 180)
{
direction = -180 + (direction - 180 );
}
return direction;
}
private:
//Predetermined Variables
int speed;
int acceleration;
int direction;
};
Does Anyone know how to do this?
Thanks :)