Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

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.
0
clintonJ
Asked:
clintonJ
1 Solution
 
AndyAinscowCommented:
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
 
grg99Commented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now