Please have look at the following code
VehicleManager.h
#pragma once
#include "Vehicle.h"
class VehicleManager
{
public:
VehicleManager(int size);
~VehicleManager(void);
bool add(Vehicle *v);
void display();
int getCount();
Vehicle **getList();
private:
int count;
int maxVehicles;
Vehicle** vehicles;
};
VehicleManager.cpp
//Other Code
Vehicle VehicleManager::**getList()
{
return vehicles;
}
//Other Code
In here, I am unable to return the array. How can I return a dynamic arrays of pointer from a function? Please help!
Apply the
**to the return type:But what you should really do is use an
std::vector<Vehicle*>if theVehicleManageris in charge of the lifetime of the dynamicallly allocatedVehicles, or anstd::vector<std::unique_ptr<Vehicle>if the caller is to take ownership. In both cases you can return it by value.