May not be redeclared outside of class..

I'm having trouble with this code in the implementation for my header file.
I keep getting error in line of code string SetCard::convert_symbol(Symbol s)
it keeps saying that it may not be redeclared outside of its class.
as well as:
error C2601: 'SetCard::convert_Symbol' : local function definitions are illegal

Any idea what could be causing this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	
			string SetCard::convert_Symbol(Symbol s){
				switch(s) {
				case OVAL:
					return "Oval";
					break;
				case SWIGGLES:
					return "Swiggles";
					break;
				case DIAMOND:
					return "Diamond";
					break;
				default:
					cout << "Error! Invalid Symbol." << endl;
					exit(1);
				}
			}

			


Header file

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
#ifndef SETCARD_
#define SETCARD_

#include <iostream>
#include <string>

using namespace std;

//new enum types
enum Color { RED, GREEN, PURPLE };

enum Symbol { OVAL, SWIGGLES, OVAL };

enum  Shading { SOLID, STRIPED, OUTLINED } ;

//Class Definition

	class SetCard {

		public:
			
			
			//Constructors----------------------------
		

			//Default Constructor
			SetCard();
			
			//Inspectors------------------------------
			

			//gets color of card
			Color getColor() const;

			//gets symbol on the card
			Symbol getSymbol() const;

			//gets shading of the card
			Shading getShade() const;

			//gets the numnber of symbols in the card
			unsigned int getNumber() const;
			
			//Mutators-------------------------------
			
			

			//Sets color of card
			void SetCard::setColor(Color &cardColor);

			//Sets symbol of card
			void SetCard::setSymbol(Symbol &cardSymbol);

			//Sets shade of card
			void SetCard::setShade(Shading &cardShade);

			//Sets number of symbol in a card
			void SetCard::setNumber(unsigned int numberofSymbol);

			//converts Color type to string
			string SetCard::convert_Color(Color c);

			//converts Symbol type to string
			string SetCard::convert_Symbol(Symbol s);

			//converts Shading type to strin
			string SetCard::convert_Shade(Shading sh);
			
			
			
			//Facilitators------------------------------
			
			

			//prints to screen
			string SetCard::toString();

			void output(ostream& out);



		private:
			Color cardColor_;
			Symbol cardSymbol_;
			Shading cardShade_;
			unsigned int numberofSymbol_;


	};




#endif  
Last edited on
When you are inside SetCard's class scope you shouldn't be using SetCard:: like on lines 49, 52, etc.
I did that and i still get the error in the same place in the method :(
it says:

error C2601: 'SetCard::convert_Symbol' : local function definitions are illegal

Based on the error (which you should have posted in your first post) and the fact that the little code snippet you provided is indented funny, I would say you're probably attempting to create a function definition within another function, which makes no sense.
I literally just copy/pasted the prototype :
 
string SetCard::convert_Symbol(Symbol s);
from the header file to the implementation file. I've done the same method before on a previous homework and it ran fine which is why I don't understand what I'm doing wrong now.

here's the whole implementation code if it helps :)

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
#include <iostream>
#include <string>
#include <sstream>
#include "SetCard.h"

using namespace std;

			//----------------------------------------
			//Constructors----------------------------
			//----------------------------------------
	

			//Default Constructor
			SetCard::SetCard(){ }


			}
			//----------------------------------------
			//Inspectors------------------------------
			//----------------------------------------

			Color SetCard::getColor() const{
				return cardColor_;
			}

			Symbol SetCard::getSymbol() const{ 
				return cardSymbol_;
			}

			Shading SetCard::getShade() const{
				return cardShade_;
			}

			unsigned int SetCard::getNumber() const{
				return numberofSymbol_;
			}
			
			//---------------------------------------
			//Mutators-------------------------------
			//---------------------------------------
			

			//Sets color of card
			void SetCard::setColor(Color &cardColor){
				cardColor_ = cardColor;
			}

			//Sets symbol of card
			void SetCard::setSymbol(Symbol &cardSymbol){
				cardSymbol_ = cardSymbol;
			}

			//Sets shade of card
			void SetCard::setShade(Shading &cardShade){
				cardShade_ = cardShade;
			}

			//Sets number of symbol in a card
			void SetCard::setNumber(unsigned int numberofSymbol){
				numberofSymbol_ = numberofSymbol;
			}

			//converts Color type to string
			string SetCard::convert_Color(Color c){
				switch(c) {
				case RED:
					return "Red";
					break;
				case PURPLE:
					return "Purple";
					break;
				case GREEN:
					return "Green";
					break;
				default:
					cout << "Error! Invalid Color." << endl;
					exit(1);
			}

			//converts Symbol type to string
			string SetCard::convert_Symbol(Symbol s){
				switch(s) 
				case OVAL:
					return "Oval";
					break;
				case SWIGGLES:
					return "Swiggles";
					break;
				case DIAMOND:
					return "Diamond";
					break;
				default:
					cout << "Error! Invalid Symbol." << endl;
					exit(1);
				}
			}


			//converts Shading type to string
			string SetCard::convert_Shade(Shading sh) {
				switch(sh){
				case SOLID:
					return "Solid";
					break;
				case STRIPED:
					return "Striped";
					break;
				case OUTLINED:
					return "Outlined";
					break;
				default:
					cout << "Error. Invalid Shading." << endl;
					exit(1);
				}
			}
			
			
			//------------------------------------------
			//Facilitators------------------------------
			//------------------------------------------
			

			//prints to screen
			string SetCard::toString(){
				//implemented later
			}

			void output(ostream& out){
				//implemented later
			}
Last edited on
You've got a dangling '}' on line 17.
Oh thanks. Removed it, still getting errors though :/
Oh whoops, didn't see it the first time. You're also missing a '}' on line 77-78 after your switch control structure.
Thanks, that finally fixed my errors :)
Registered users can post here. Sign in or register to post.