Compile Time Recursion Warning

I've got a visual c++ application that i ported to .NET.  I have only fixed the compile time errors.  However, I get one compile warning for a line within one of my functions:

"recursive on all control paths, function will cause runtime stack overflow"

void C2DMyArray::SetSize(int newX, int newY, int nGrowBy)
{
      SetSize( newX*newY, nGrowBy);
      m_nSizeX = newX;
      m_nSizeY = newY;
}

where C2DMyArray is derived from CTypedPtrArray.

Any thoughts on how to avoid this recursion?

Thanks ahead of time.
clintonJAsked:
Who is Participating?
 
grg99Connect With a Mentor Commented:
It looks like you intend to call some overloaded SetSize that takes two arguments instead of three.

The compiler is thinking you want the function to call itself, which makes no sense, and the number of arguments is wrong.

How about you rename the 2-parameter function to something like "SetSize2", or rename the outer one to "SetSize3"?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
void C2DMyArray::SetSize(int newX, int newY, int nGrowBy)
{
  //    SetSize( newX*newY, nGrowBy);   <--- Don't call it here, stop the recursion
      m_nSizeX = newX;
      m_nSizeY = newY;
}


Why would you want to call the function from inside itself?  Seems like you have an error in your logic.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.