T O P I C ��� R E V I E W
|
Daniel Butler
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?
|
Charles Capps
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?
|
Daniel Butler
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...
|
Cartman
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.
|
Daniel Butler
Member # 1689
|
posted
After this, I believe it.
|