c++ - Excessive arguments error for recursive reverse string method -
i'm trying program recursive function prints reverse of string, however, compiler keeps saying has many arguments. wrong recursive program?
#include <iostream> using namespace std; void reversedisplay (const string& s) { int length=s.size()-1; if (length==0) return; reversedisplay(s, length); } void reversedisplay (const string& s, int n) { if(n==1) cout <<s[n]; else { cout << s[n]; reversedisplay(s, n-1); } } int main() { string s="12345"; reversedisplay(s); return 0; }
try forward declaration:
void reversedisplay (const string& s, int n);
put before void reversedisplay (const string& s)
.
Comments
Post a Comment