Function

Jan 30, 2016 at 1:43pm
Function that generate a pointer type like node<itemtype>*getNext() what is this actually ?i having confusion
Jan 30, 2016 at 2:01pm
i having confusion


You seem to be always "having confusion". Is it that, or are you still trolling?

Consider getting a good text book and reading it. Start from the basics.
Jan 30, 2016 at 2:12pm
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) return nullptr;
    else if (no data found) return nullptr;
    else return foundData;
}

The problem here is that the caller has no way to distinguish between "an error occurred" and "there is no data to return."

Jan 31, 2016 at 3:25am
i also can set parameter as pointer and return pointer right?
Jan 31, 2016 at 4:17pm
Yes.
Topic archived. No new replies allowed.