What is this error?

Hello

i made a return function in my class
1
2
3
4
5
6
7
8
9
const hgeSprite* gameLogic::getEnemySprite() const
{
	for(int render = 0; render < this->SIZE; render++)
	{
		return this->enemies[render]->getSprite();

	}

}


it gives me the warning

warning C4715: 'gameLogic::getEnemySprite' : not all control paths return a value

Anyone that knows what this is? and how to fix it?
Ignoring your rather strange looking loop which doesn't make sense to me.

If a function has been declared as having a return value, then every possible routes to exit that function
must have a return statement.
Consider the example below:
If the if statement tests true then the if block is executed - we exit the function in this block
and we return a value - OK.

If the if tests fails then we skip past the if block to line 9 - as you can see we reach the end of the function - but we have not specified a return value

1
2
3
4
5
6
7
8
9
10
11
12
13
int someFunction()
{

    if (/* insert test condition here*/)
    {
        //insert some code here
         return /*insert return value here*/;
    }
    
     //maybe some more code here
    //Problem - need to do a return value here 
    
}
What must your function do? Do you realize that only one (the first one) return has an effect?

The warning appears because if SIZE==0 then no iteration is performed and there is no return to be encountered before reaching the closing '}' of the function body.
Last edited on
Thanks it works now but i keep getting this strange error when i try to run my hierarchy connected to my main
1
2
3
4
5
6
gameObject.obj : error LNK2005: "class HGE * hge" (?hge@@3PAVHGE@@A) already defined in enemy.obj
main.obj : error LNK2005: "class HGE * hge" (?hge@@3PAVHGE@@A) already defined in enemy.obj
ship.obj : error LNK2005: "class HGE * hge" (?hge@@3PAVHGE@@A) already defined in enemy.obj
HGEenemy.obj : error LNK2005: "class HGE * hge" (?hge@@3PAVHGE@@A) already defined in enemy.obj
HGEship.obj : error LNK2005: "class HGE * hge" (?hge@@3PAVHGE@@A) already defined in enemy.obj
gameLogic.obj : error LNK2005: "class HGE * hge" (?hge@@3PAVHGE@@A) already defined in enemy.obj


This looks like a header file problem:

1. You have not put proper header guards in your header file(s).

OR

2. You have placed a global variable in a header file. This header file is being included in several cpp files
so you are getting multiple definition errors for the variable.
Topic archived. No new replies allowed.