What's the point of this variable?

So my book has this example program meant to show how to use stacks and queues. It uses a stack to determine if a group of characters in a queue is parenthetically correct(every "(" has a matching ")" in the right place, etc). Here's the function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
template <class T>
bool testQueue( Queue<T> &q )
{
	const string balTokenTableOpen ( "{[(" );
	const string balTokenTableClose( "}])" );
	const string quoteTokens( "'\"" );
	Stack<T> s;
	char c, cl;
	string test; //What's the point of this variable?
	int pos;
	bool esc = false;
	bool OK = true;

	while ( !( q.isEmpty() ) && OK )
	{
		q.dequeue( c );
		test = c;  // assigned to c here

		if ( esc )  // ignore the character after the escape character
		{
			esc = false;
			continue;
		}

		if ( c == '\\' )
		{
			esc = true;
		}
		else if ( balTokenTableOpen.find( test ) != string::npos ) //Why can't you just use c instead of test?
		{
			s.push( c );
		}
		else if ( ( pos = balTokenTableClose.find( test ) ) != string::npos  ) //Used again here.
		{
			if ( s.isEmpty() )
				OK = false;
			else
			{
				s.pop( cl );
				if (  balTokenTableOpen.at( pos ) != cl )
					OK = false;
			}
		}
		else if ( quoteTokens.find( test ) != string::npos ) // And again.
		{
			char temp;			
			s.getTop( temp );  // No need to check catch an error here because
			
			if ( s.isEmpty() || temp != c ) // we will catch empty stack here.  Notice how short-circuit evaluation is used.
				s.push( c );
			else
			{
				s.pop();
			}
		}
	}

	if ( esc || !( s.isEmpty() ) )
		OK = false;

	return OK;
}


I'm wondering why the program declares the string "test" and uses it when it seems like it could just use "c" instead. The book claims that there is a reason, but doesn't specify it. I tried to figure it out, and I even replaced all uses of "test" with "c", ran the program, and it worked exactly the same with no errors. I see absolutely no point in using test. Is there something I'm missing?
Nope. There really is no point to 'test'.
Topic archived. No new replies allowed.