Function parameter out of scope

I have a function that writes the binary of a character (got it on stackoverflow.com):

1
2
3
4
5
6
7
8
9
10
11
void binary(char c) {
   int remainder;

   if((int)c <= 1) {
       std::cout << (int)c;
       return;
   }
   remainder = (int)c % 2;
   binary((int)c >> 1);    
   std::cout << remainder;
}


I was trying to make a similar function that return the binary in a string:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
string Binary(const char& c) {
	int r;
	string out;
	
	if ((int)c <= 1) {
		out += (int)c;
		return "";
	}
	r = (int)c % 2;
	Binary((int)c >> 1);
	
	stringstream ss;
	ss << r;
	out += ss.str();
	return out;
}


The function might not be finished yet (I don't know does it work well) so I was debugging to finish it of course and I found that the identifier 'c' was out of scope wtf!!! Why??? And I want the function to be finished, too. Thanks.
You must have misinterpreted the information the debugger gave you. c is in scope throughout the whole function.
No, your debugger is wrong it seems. Have you tried recompile everything to see if that makes the error go away?
I think it's not gonna work.

UPDATED: And it did not work.
Last edited on
Topic archived. No new replies allowed.