Error: missing function header (old-style formal list?)

Below is a section of code from my program.

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
void textcolor (string f, int fi, string b, int bi); {

	switch (f){
		case "Green": f=FOREGROUND_GREEN; break;
		case "Blue": f=FOREGROUND_BLUE; break; 
		case "Red": f=FOREGROUND_RED; break;
		case "Yellow": f=FOREGROUND_RED | FOREGROUND_GREEN; break;
		case "Cyan": f=FOREGROUND_GREEN | FOREGROUND_BLUE; break;
		case "Purple": f=FOREGROUND_BLUE | FOREGROUND_RED; break;
		case "White": FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; break;
		default: cout << "FOREGROUND COLOR NOT SPECIFIED" << endl;};
			if (fi==1) {fi=| FOREGROUND_INTENSITY} else {bi=0};

	switch (b){
		case "Green": b=BACKGROUND_GREEN; break;
		case "Blue": b=BACKGROUND_BLUE; break; 
		case "Red": b=BACKGROUND_RED; break;
		case "Yellow": b=BACKGROUND_RED | BACKGROUND_GREEN; break;
		case "Cyan": b=BACKGROUND_GREEN | BACKGROUND_BLUE; break;
		case "Purple": b=BACKGROUND_BLUE | BACKGROUND_RED; break;
		case "White": b=BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN; break;
		default: cout << "BACKGROUND COLOR NOT SPECIFIED" << endl; };
			if (BI==1) {bi=| BACKGROUND_INTENSITY} else {bi=0};

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), f << fi);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), b << bi);}



Below is the compiler error I get in Microsoft Visual C++ 2008 Express

(line 1) error C2447: '{' : missing function header (old-style formal list?)

I don't know what this error means, or how to fix it. Any help is appreciated.
Last edited on
There is a semicolon in the first line, where there should be none.
Again I overlook the small things. Now I know what that error means though.

Now that I fixed that one, I get a whole bunch of other errors.

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
void textcolor (string f, int fi, string b, int bi) {

	switch (f){
		case "Green": f="FOREGROUND_GREEN"; break;
		case "Blue": f="FOREGROUND_BLUE"; break; 
		case "Red": f="FOREGROUND_RED"; break;
		case "Yellow": f="FOREGROUND_RED| FOREGROUND_GREEN"; break;
		case "Cyan": f="FOREGROUND_GREEN | FOREGROUND_BLUE"; break;
		case "Purple": f="FOREGROUND_BLUE | FOREGROUND_RED"; break;
		case "White": f="FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN"; break;
		default: cout << "FOREGROUND COLOR NOT SPECIFIED" << endl;};
			if (fi==1) fi="| FOREGROUND_INTENSITY" else fi=0;

	switch (b){
		case "Green": b="BACKGROUND_GREEN"; break;
		case "Blue": b="BACKGROUND_BLUE"; break; 
		case "Red": b="BACKGROUND_RED"; break;
		case "Yellow": b="BACKGROUND_RED | BACKGROUND_GREEN"; break;
		case "Cyan": b="BACKGROUND_GREEN | BACKGROUND_BLUE"; break;
		case "Purple": b="BACKGROUND_BLUE | BACKGROUND_RED"; break;
		case "White": b="BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN"; break;
		default: cout << "BACKGROUND COLOR NOT SPECIFIED" << endl; };
		if (bi==1) bi="| BACKGROUND_INTENSITY"; else bi=0;
//To be honest, I'm not really sure whether the colors (ie FOREGROUND_RED) should be in quotes or not, since they are used as parameters.
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), f fi);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), b bi);}



1>(3) : error C2450: switch expression of type 'std::string' is illegal
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>(4) : error C2051: case expression not constant
1>(5) : error C2051: case expression not constant
1>(6) : error C2051: case expression not constant
1>(7) : error C2051: case expression not constant
1>(8) : error C2051: case expression not constant
1>(9) : error C2051: case expression not constant
1>(10) : error C2051: case expression not constant

Duh, of course it's not going to be constant or you wouldn't need a switch case statement.
1>(11) : warning C4065: switch statement contains 'default' but no 'case' labels

Umm.. I'm pretty sure it does. See lines 4-10
1>(12) : error C2440: '=' : cannot convert from 'const char [23]' to 'int'
1> There is no context in which this conversion is possible

I'm not asking you to. You should be converting from string to string.
1>(14) : error C2450: switch expression of type 'std::string' is illegal
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

You tell me it's wrong when I use char var[#] too, what am I supposed to use?
1>(15) : error C2051: case expression not constant
1>(16) : error C2051: case expression not constant
1>(17) : error C2051: case expression not constant
1>(18) : error C2051: case expression not constant
1>(19) : error C2051: case expression not constant
1>(20) : error C2051: case expression not constant
1>(21) : error C2051: case expression not constant
1>(22) : warning C4065: switch statement contains 'default' but no 'case' labels
1>(23) : error C2440: '=' : cannot convert from 'const char [23]' to 'int'
1> There is no context in which this conversion is possible
1>(25) : error C2146: syntax error : missing ')' before identifier 'fi'
1>(25) : error C2664: 'SetConsoleTextAttribute' : cannot convert parameter 2 from 'std::string' to 'WORD'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>(25) : error C2059: syntax error : ')'
1>(26) : error C2146: syntax error : missing ')' before identifier 'bi'
1>(26) : error C2664: 'SetConsoleTextAttribute' : cannot convert parameter 2 from 'std::string' to 'WORD'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>(26) : error C2059: syntax error : ')'
you can't use the switch statement for strings, it's only for integral type.
The SetConsoleTextAttribute takes a WORD (unsigned short) as argument, not a string
Last edited on
Okay, I'll convert this to if-else and post my next set of screw-ups ;). Thanks.
Topic archived. No new replies allowed.