I need to combine these two functions. and need help in so:
int Triangle(GzRender *render, int numParts, GzToken *nameList,GzPointer *valueList)
{
if (on_screen)
{
return Position(render, pos);
}
}
int Position(GzRender *render, GzCoord vertexList[3])
{
GzCoord *pv[3];
int i,j;
pv[0] = &vertexList[0];
pv[1] = &vertexList[1];
pv[2] = &am开发者_如何学运维p;vertexList[2];
//more function code in here
}
Can anyone help me with this.
Regards
Normally, separating out functions is a better, more common practice (and one of the main tasks during refactoring). That being said, you can "combine" these simply by doing:
int Triangle(GzRender *render, int numParts, GzToken *nameList,GzPointer *valueList)
{
if (on_screen)
{
//function code in here, working on "pos" instead of vertexList
// return value
}
// return some other value here?
}
The first poster (Reed Copsey) is correct about the fact that it's generally better to keep the functions separate.
Have you considered using the inline
directive?
http://www.codersource.net/cpp_tutorial_inline_functions.html
Technically it's only a 'compiler hint' but you could try it. What it does is tell the compiler that you would like to include the body of the method denoted as inline in any other methods that call it. It's better from a maintenance standpoint, and should achieve what you are aiming for without the headaches of 'cut-and-paste' coding.
int Triangle(GzRender *render, int numParts, GzToken *nameList,GzPointer *valueList)
{
if (on_screen)
{
return Position(render, pos);
}
}
inline int Position(GzRender *render, GzCoord vertexList[3])
{
//function code in here
}
Flip them around if it isn't compiling. Put "Position" in front of "Triangle"
精彩评论