Inside one of my classes i've got a
Reservation * availability[30] = {nullptr};
(which I of course initialize later with some values).
Nevertheless, I've got a getReservations() function which is supposed to return a reference to that array of 30 elements, so that it can be used like:
getReservations()[i] ...
How should I declare that function?
The syntax for declaring a function that returns the array by reference is this:
Reservation * (& getReservations())[30];
Of course, as you can see, you shouldn't use this in real life. Instead do it with a type alias:
using Reservations = Reservation * [30];
Reservations & getReservations();
Or, because arrays aren't bounds-checked anyway, just return a pointer which you can then index like an array:
Reservation * getReservations();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With