It's just what it says: a function that returns a pointer.
When you write a function that returns a pointer, you need to be very clear with yourself and code that calls the function about a few things:
- Can the pointer be null?
- How long is the pointed-at data valid?
- Does the pointer need to be deleted by the caller?
Also, try to avoid this common mistake:
1 2 3 4 5 6
Data *findData(args) {
get the data
if (error occurred) returnnullptr;
elseif (no data found) returnnullptr;
elsereturn foundData;
}
The problem here is that the caller has no way to distinguish between "an error occurred" and "there is no data to return."