Getters and Setters Acting Strange (or maybe Code::Blocks)

I have two classes, a Deck.h and a Card.h. Of particular interest are the following functions in Card.h, which are used to make particular cards:
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
void Card::makeCard( int type, int specific )
{
    switch( type )
    {
    case 1:
        setEffect( HAZARD );
        createHazCard( specific );
        break;
    case 2:
        setEffect( REMEDY );
        createRemCard( specific );
        break;
    case 3:
        setEffect( SAFETY );
        createSafeCard( specific );
        break;
    case 4:
        setEffect( DISTANCE );
        createDistCard( specific );
        break;
    default:
        setEffect( GOSTOP );
        createGoStopCard( specific );
        break;
    }
}


void Card::createDistCard( int specific )
{
    setMagnitude( specific );
    string miles;
    switch( specific / 25 )
    {
    case 1:
        miles = "25";
        break;
    case 2:
        miles = "50";
        break;
    case 3:
        miles = "75";
        break;
    case 4:
        miles = "100";
        break;
    case 8:
        miles = "200";
        break;
    }

    setName( miles );
}

void Card::createGoStopCard( int specific )
{
    switch( specific )
    {
    case 1:
        setMagnitude( 100 );
        setName( "Go!" );
        break;
    default: //Case 0
        setMagnitude( 0 );
        setName( "Stop!" );
        break;
    }
}

void Card::createHazCard( int specific )
{
    switch( specific )
    {
    case TIRE:
        setHazType( TIRE );
        setName( "Flat Tire!" );
        setMagnitude( 100 );
        break;
    case ACCIDENT:
        setHazType(ACCIDENT );
        setName( "Accident!" );
        setMagnitude( 100 );
        break;
    case GAS:
        setHazType( GAS );
        setName( "Out of Gas!" );
        setMagnitude( 100 );
        break;
    case LIMIT:
        setHazType( LIMIT );
        setName( "Speed Limit!" );
        setMagnitude( 50 );
        break;
    }
}

void Card::createRemCard( int specific )
{
    cout << "\n\nMakin\' me a rem card!\n\n";
    switch( specific )
    {
    case TIRE:
        cout << "Spare tire coming right up!!!\n\n";
        setHazType( TIRE );
        setName( "Spare Tire" );
        setMagnitude( 100 );
        cout << getName() << endl;
        break;
    case ACCIDENT:
        cout << "Repair toolz!!!\n\n";
        setHazType( ACCIDENT );
        setName( "Repairs" );
        setMagnitude( 100 );
        cout << getName() << endl;
        break;
    case GAS:
        cout << "Gas container!!!\n\n";
        setHazType( GAS );
        setName( "Gasoline" );
        setMagnitude( 100 );
        cout << getName() << endl;
        break;
    case LIMIT:
        cout << "Screw you, speed limit!!!\n\n";
        setHazType( LIMIT );
        setName( "End of Limit" );
        setMagnitude( 50 );
        cout << getName() << endl;
        break;
    }
}

void Card::createSafeCard( int specific )
{
    switch( specific )
    {
    case 1:
        setHazType( TIRE );
        setName( "Puncture-Proof!" );
        setMagnitude( 100 );
        break;
    case 2:
        setHazType( ACCIDENT );
        setName( "Driving Ace!" );
        setMagnitude( 100 );
        break;
    case 3:
        setHazType( GAS );
        setName( "Extra Tank!" );
        setMagnitude( 100 );
        break;
    case 4:
        setHazType( LIMIT );
        setName( "Right-of-Way!" );
        setMagnitude( 100 );
        break;
    }
}


There are cout statements in createRemCard because it was giving me trouble. The functions are called in Deck.h, and are used to create the cards that will go into the deck. Each type of card is created, and I have tested every function: everyone except for createRemCard is fine. The problem is as follows:

I try to display the names of the remedy (rem) cards in Deck.h where the deck is being filled:
1
2
3
4
5
6
7
8
9
10
11

    Card Repairs;//6
    Repairs.makeCard( REMEDY, ACCIDENT );
    Card Gasoline;//6
    Repairs.makeCard( REMEDY, GAS );
    Card SpareTire;//6
    Repairs.makeCard( REMEDY, TIRE );
    Card EndOfLimit;//6
    Repairs.makeCard( REMEDY, LIMIT);

    cout << "\n\nHere are my rems: " << endl << "1)" << Repairs.getName() << endl << "2)" << Gasoline.getName() << endl << "3)" << SpareTire.getName() << endl << "4)" << EndOfLimit.getName() << endl ;


The cout statements within createRemCard trigger, and display all their messages, including the card names (as they should). However, when I list my remedy cards at the end there, Repairs.getName() returns me "End of Limit" and the rest of the names are empty. That said, the same basic thing for other card types (Distance, Hazard, etc.) work totally fine, their names are displayed perfectly. The getName() and setName() functions for all card types are the same (they are all objects of the same class):
1
2
string getName() { return name; }
void setName( string val ) { name = val; }

What could be going wrong? Is Code::Blocks (which I am using) just being a troll?

Thanks in advance!

1
2
string getName() { return name; }
void setName( string val ) { name = val; }
these should be Card::getName and Card::setName
I have them written that way in Card.h. They work fine. The error is actually incredibly stupid, I saw it after taking another look at my code just now. Every time I call makeCard in that last code chunk there, I call it on Repairs every time, as opposed to Gasoline, SpareTire and EndOfLimit. Foolish me!
Topic archived. No new replies allowed.