Hi,
[EDIT 1 - added third pointer syntax (Thanks Alex)]
Which method would you prefer for a DAL and why out of:
Car& DAL::loadCar(int id) {}
bool DAL::loadCar(int id, Car& car) {}
Car* DAL::loadCar(int id) {}
If unable to find the car first method returns null, second method returns false.
The second method would create a Car object on the heap and populate with data queried from the database. Presumably (my C++ is very rusty) that would mean code along the lines of:
Car& DAL::loadCar(int id)
{
Car *carPtr = new Car();
Car &car= *carPtr;
car.setModel(/* value from database */);
car.setEngineSize(/* value from database */);
// etc
return car;
}
Thanks