recursion within a class

This is a discussion on recursion within a class within the C++ Programming forums, part of the General Programming Boards category; Is there something about having a class member function try to call itself that will automatically fail that would prevent ...

  1. #1
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179

    recursion within a class

    Is there something about having a class member function try to call itself that will automatically fail that would prevent recursion within a class and how do you avoid it?

    I'm trying to write a c++ conversion of a C program so I can encapsulate a certain functionality within a class, but the functionality relies on recursion to work. But when it comes to the point of making the call it's like it doesn't even run the function and automatically returns a 0. Is this normal? How do I fix it.

    I could show you my code if you like but it's awfully convoluted right now.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    No, recursion works with member functions just as it does with free functions. Of course, it is always possible to substitute recursion with iteration, using an explicit stack if necessary.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    Okay, this was a classic example of me programming too late at night and shooting of the question that my fatigue prevented me from seeing.

    I had a line in my recursive function that measured how much time it took to run so that it didn't keep dead ends that I haven't programmed it to be smart enough to find the first time. Of course with debugging so I can step through the program the 1 second time limit was expiring before it iterated once.

    So if I could I'd delete this thread. Once again, laserlight, thanks for the quick and knowledgeable reply.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  3. Replies: 7
    Last Post: 05-26-2005, 10:48 AM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 07:57 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21