|
-
April 17th, 2004, 09:34 PM
#1
Inheritance problem
Hello
I'll describe my problem. I've got a vehicle class (cVehicle), and two 'heirs', car (cCar)and van (cVan). The vehicle class has atributes X and Y, car has C and van has V, and both heirs inherit X and Y.
i have a class called Vehiclefactory which has a method which recieves a string with the atributes and it must return a Cvehicle object. Then i must add it to a list.
Code:
CVehiculo* temp = Vehiclefactory.Create (" string with atributes");
VehicleList.Add (temp);
Inside Vehiclefactory.create function, if i get a string with a C, i must create a car, and if i get a string with a V i must create a van
Code:
if (c==C)
{
cCar * car = new cCcar(X,Y,C);
return aut;
}
if (c==V)
{
cVan * van = new cVan(X,Y,V);
return van;
}
but the function returns a cVehicle class, so i lost the car or van atribute.
Code:
class cVehiclefactory
{
private:
FILE *data;
public:
void read (char * filename);
cvehiculo * Create (char data[51]);
};
i really need the create function to return a Cvehicle class, but i need to actualle return a car or a van, to be able to see its atributes and then to add it to a list. these lines of code must be in the program
Code:
CVehiculo* temp = Vehiclefactory.Create (" string with atributes");
VehicleList.Add (temp);
hope you can help me!!
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|