Daniel Butler
I'm a Singapore where is my boat
Member # 1689
posted
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?
Registered: Jul 2005
| IP: Logged
Charles Capps
We appreciate your concern. It is noted and stupid.
Member # 9
posted
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?
Registered: Mar 1999
| IP: Logged
Daniel Butler
I'm a Singapore where is my boat
Member # 1689
posted
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...
Registered: Jul 2005
| IP: Logged
Cartman
just made by the Presbyterian Church
Member # 256
posted
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.
Registered: Nov 1999
| IP: Logged
Daniel Butler
I'm a Singapore where is my boat
Member # 1689
posted
After this, I believe it.
Registered: Jul 2005
| IP: Logged