Adding a new zero-length element with name: "MyElement". Compiles but gives the warning:
warning C4715: 'MyElement::commitState' : not all control paths return a value
Couldn`t make out what the warning implies. Any help is appreciated. Thanks.
warning while adding element
Moderators: silvia, selimgunay, Moderators
Re: warning while adding element
The function prototype for commitState is
int commitState( )
so you need to return an integer value. You probably have some if statements, like
if ( do stuff successfully )
return ( number that signals success );
but there are ways to go through your function and never get to the "return" part.
So you could add a last line to the function
return (some number that means there was a mistake);
cheers,
alisa
int commitState( )
so you need to return an integer value. You probably have some if statements, like
if ( do stuff successfully )
return ( number that signals success );
but there are ways to go through your function and never get to the "return" part.
So you could add a last line to the function
return (some number that means there was a mistake);
cheers,
alisa
eroz wrote:Adding a new zero-length element with name: "MyElement". Compiles but gives the warning:
warning C4715: 'MyElement::commitState' : not all control paths return a value
Couldn`t make out what the warning implies. Any help is appreciated. Thanks.
Thanks for the response. Isn`t what I have below supposed to increase "code" if (successfull) and return an error message if (unsuccessfull), thus cover both cases if the function is successfull or not? Thanks.
Here is what I have:
int ZeroLength::commitState()
{
int code=0;
// call element commitState to do any base class stuff
if ((code = this->Element::commitState()) != 0)
{
opserr << "MyElement::commitState () - failed in base class";
}
// commit 1d materials
for (int i=0; i<numMaterials1d; i++)
{ code += theMaterial1d->commitState();
return code;
}
}
Here is what I have:
int ZeroLength::commitState()
{
int code=0;
// call element commitState to do any base class stuff
if ((code = this->Element::commitState()) != 0)
{
opserr << "MyElement::commitState () - failed in base class";
}
// commit 1d materials
for (int i=0; i<numMaterials1d; i++)
{ code += theMaterial1d->commitState();
return code;
}
}
eroz wrote:Thanks for the response. Isn`t what I have below supposed to increase "code" if (successfull) and return an error message if (unsuccessfull), thus cover both cases if the function is successfull or not? Thanks.
Right idea, you just need to return code *after* the loop.
Here is what I have:
int ZeroLength::commitState()
{
int code=0;
// call element commitState to do any base class stuff
if ((code = this->Element::commitState()) != 0)
{
opserr << "MyElement::commitState () - failed in base class";
}
// commit 1d materials
for (int i=0; i<numMaterials1d; i++)
{ code += theMaterial1d->commitState();
return code;
}
// You should return code here, and the value will
//be the sum of the number of errors.
}