2nd switch gets error..

I am writing a program that will instantiae with 2 colors for a flag, and accept two colors from the user to change them. On my second switch I get a "error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'enum color' (or there is no acceptable conversion)" message..I have talked with another student (who is much better than I) and we are both confused by this. I only get the error for the second switch statement(it lists all 5 of them)...

Here's the code:
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
cFlag::cFlag()
	{
		cout<<"Construcor go!"<<endl;
		color *cColorOne = new color;
		color *cColorTwo = new color;
		int iChoice;
		int iChoiceTwo;

		cout<< "Please enter your first color choice" << endl;
		cout << "\t 1 - red\n";
		cout << "\t 2 - white\n";
		cout << "\t 3 - blue\n";
		cout << "\t 4 - green\n";
		cout << "\t 5 - yellow\n";
		cin  >>  iChoice;
		cout <<  endl;

		switch(iChoice)
			{
				case 1:
					cColor = red;
					break;
				case 2:
					cColor = white;
					break;
				case 3:
					cColor = blue;
					break;
				case 4:
					cColor = green;
					break;
				case 5:
					cColor = yellow;
					break;
			
		}
		cout << endl;
	
		
	cout<< "Please enter your second color choice" << endl;
	cout << "\t 1 - red\n";
	cout << "\t 2 - white\n";
	cout << "\t 3 - blue\n";
	cout << "\t 4 - green\n";
	cout << "\t 5 - yellow\n";
	cin  >>  iChoiceTwo;
	cout <<  endl;
	
	switch(iChoiceTwo)
	{	
			case 1:
				cColorTwo = red;
				break;
			case 2:
				cColorTwo = white;
				break;
			case 3:
				cColorTwo = blue;
				break;
			case 4:
				cColorTwo = green;
				break;
			case 5:
				cColorTwo = yellow;
				break;
		}
	cout << endl;
	}

	void cFlag::SetColor (color cColorToSet)
		{
			cColor = cColorToSet;
		}

	color cFlag::GetColor()
		{
			return(cColor);
		}

	void cFlag::SetColorTwo (color cColorToSet)
		{
			cColorTwo = cColorToSet;
		}
	color cFlag::GetColorTwo()
		{
			return(cColorTwo);
		}

		;


Thanks
Trust the compiler:
Look at Line 5 and look at line 52( 55, 58, 61,64) and it will just come to you in a flash!
no, it didn't, haha, I am so far back, l have had my comp for 3 of 17 weeks of class, my instructor maintains that since we have gone over this, he won't help...
I did change cColorTwo to cColor like the first switch, and it compiles and runs but stops after the second color choice is made...error:

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xBE8 has exited with code 4726424 (0x481E98).
The program 'F:\FlagAgain\Flag\Debug\Flag.exe' has exited with code 4726424 (0x481E98).
There is some confusion with your variable names :
cColor,cColorOne and cColorTwo.

The compiler did not complain about cColor in setch statement 1 - so you have a member variable my this name.

In switch statement 2 - the cColorTwo visible at that time is the POINTER cColorTwo you setup in line5.

Further down in line 82 you assign a value to a variable called cColorTwo - so obviously you have a member variable by that name.

So... The two pointers in Line 4 and 5 are the problems because cColorTwo pointer is creating a name clash, you don't do anything with the cColorOne pointer AND as soon as the constructor finishes their value will be lost as they are local variable - and but the new colors created will still be there so that is a memory leak as well.


ahhh yes I noticed that discrepency, when I changed the 1st switch statement variable to cColorOne, I get the same error as on the 2nd switch statement.
Here, maybe the entire code will help:
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//Flag.h


enum color { red=1, white, blue, green, yellow};

class cFlag {

private:

    color cColor;
    color cColorTwo;
public:
    cFlag();
    ~cFlag();
    
    void SetColor ( color );
    color GetColor( void );

    void SetColorTwo( color );
    color GetColorTwo( void );

protected:

};


//Flag.cpp


#include <iostream>
#include <string>

using namespace std;

#include "Flag.h"


cFlag::cFlag()
    {
        cout<<"Construcor go!"<<endl;
        color *cColorOne = new color;
        color *cColorTwo = new color;
        int iChoice;
        int iChoiceTwo;

        cout<< "Please enter your first color choice" << endl;
        cout << "\t 1 - red\n";
        cout << "\t 2 - white\n";
        cout << "\t 3 - blue\n";
        cout << "\t 4 - green\n";
        cout << "\t 5 - yellow\n";
        cin  >>  iChoice;
        cout <<  endl;

        switch(iChoice)
            {
                case 1:
                    cColor = red;
                    break;
                case 2:
                    cColor = white;
                    break;
                case 3:
                    cColor = blue;
                    break;
                case 4:
                    cColor = green;
                    break;
                case 5:
                    cColor = yellow;
                    break;
            
        }
        cout << endl;
    
        
    cout<< "Please enter your second color choice" << endl;
    cout << "\t 1 - red\n";
    cout << "\t 2 - white\n";
    cout << "\t 3 - blue\n";
    cout << "\t 4 - green\n";
    cout << "\t 5 - yellow\n";
    cin  >>  iChoiceTwo;
    cout <<  endl;
    
    switch(iChoiceTwo)
    {    
            case 1:
                cColorTwo = red;
                break;
            case 2:
                cColorTwo = white;
                break;
            case 3:
                cColorTwo = blue;
                break;
            case 4:
                cColorTwo = green;
                break;
            case 5:
                cColorTwo = yellow;
                break;
        }
    cout << endl;
    }

    void cFlag::SetColor (color cColorToSet)
        {
            cColor = cColorToSet;
        }

    color cFlag::GetColor()
        {
            return(cColor);
        }

    void cFlag::SetColorTwo (color cColorToSet)
        {
            cColorTwo = cColorToSet;
        }
    color cFlag::GetColorTwo()
        {
            return(cColorTwo);
        }

    ;


//Main.cpp


#include <iostream>
#include <string>

using namespace std;

#include "Flag.h"

extern void main(void);

extern void main()

{
    cFlag *oFlag = new cFlag();

    color cTemp;
    color cTempTwo;

    cout<<"Please choose your favorite two colors for the flag, the colors now are red and white."<<endl;
    cTemp = oFlag->GetColor();
    
    switch(cTemp)
    {
        case red:
            cout << "red ";
            break;
        case white:
            cout << "white ";
            break;
        case blue:
            cout << "blue ";
            break;
        case green:
            cout << "green";
            break;
        case yellow:
            cout << "yellow";
                break;
    }
    cout<< endl;

{
    cTempTwo = oFlag->GetColorTwo();
    switch(cTempTwo)
    {
        case red:
            cout << "red ";
            break;
        case white:
            cout << "white ";
            break;
        case blue:
            cout << "blue ";
            break;
        case green:
            cout << "green";
            break;
        case yellow:
            cout << "yellow";
            break;
    }
    cout<< endl;
    cout<<"The new colors of the flag are: "<<cTemp<< " and "<<cTempTwo<<endl;
}
}

thanks again
Last edited on
Bump, STILL haven't got this worked out....
closed account (z05DSL3A)
Delete line 41 and 42.
Thank you I will give it a go.
Topic archived. No new replies allowed.