I've got an assignment for my C++ class that I'm a bit confused about... There's a class MyString that has a public method length() which returns an int and takes no arguments. We're supposed to implement it using indirect recursion with a private function called recursiveLength that does take a value... thing is, I don't really understand how to use a function that has no parameters recursively. Can anybody help me out?
Posted by Charles Capps (Member # 9) on :
You'll have to store the state of the function as a property of the object, then just have the function refer to that. At least that's how it'd be done in any other OO language.
That being said, WTF would you ever need a recursive function for to measure a string? Shouldn't there be some sort of standard library call?
Posted by Daniel Butler (Member # 1689) on :
We're not allowed to use strlen() because we're supposed to be writing the standard library functions right now to learn how they work. Still, I wouldn't do it recursively if he didn't make us...
Posted by Cartman (Member # 256) on :
Half-assed assignments about recursion that demonstrate the concept in the most artificial (ie. retarded) way imaginable have mutilated more CS students than BASIC ever did. Fact.
Posted by Daniel Butler (Member # 1689) on :