• Register
100 points
7 4

Today we are discussing the error control may reach the end of non-void function in C++
This error comes because of some mistake in your algorithm. For better understanding let us take an example from the web.

if (outer-condition-1)
    if (inner-condition-1)
        return 1
else if (outer-condition-2)
    if (inner-condition-2)
        return -1
else
    return 0

Now make a  flowchart for this code:

 

image

As we can see, if any of the function blocks come at a false condition, then there is nothing to return to. It means this block is not executable at all. The function will never return a statement and this cannot happen according to the compiler. Every function must always return something.

Now is the time to resolve it?
There are some ways to resolve it given below.
1. It is the simplest one, just add return statements at the end, it will hide problems that encounter the error, but makes the code much more difficult to find another error.
2. If you are sure that your code is working as it should then you can modify your code like.
3. If you want to return a different result at any point then you can use it nested but you have some work left to do ... you have to add return statements for every outcome.

100 points
7 4