I need to create a vector that can contain my parent class and sub class data.
This is what i do..
Vehicle is the parent class
Car is the child class
About Car.cpp , it got the following
struct Point
{
int x,y
};
class Car : public Vehicle
{
private:
Point wheelPoint[4];
double area;
public:
void setPoint();
};
void Car::setPoint()
{
int xData,yData;
cout << "Please enter X:";
cin >> xData;
cout << "Please enter Y:";
cin >> yData;
wheelPoint[i].x = xData;
wheelPoint[i].y = yData;
}
Then at my main.cpp
At my main.cpp
vector<VehicleTwoD> list;
VehicleTwoD *vehicle;
Car *car = new Car;
string vehicleName;
cout << "Please input name of vehicle";
cin >> vehicleName;
vehicle = new Car;
car->setPoint();
list.push_back( Vehicle() );
list.back().setName(vehicleName);
Here the issues.. how i put my wheelPoint of car into this vector also.
What i want to achieve is a vector that can contain
Vehicle Name: Vehicle Name (private variable at Vehicle - Parent Class)
Wheel Point[0]: Point (X,Y) ( private var at Car - Child Class)
Wheel Point[1]: Point (X,Y) ( private var at Car - Child Class)
Wheel Point[2]: Point (X,Y) ( private var at Car - Child Class)
Wheel Point[3]: Point (X,Y) ( private var at Car - Child Class)