contructor/variables/objects

If I do the below:
1
2
discard discard;
discard.d.playingDeck.createDeck();

I am creating a object of the class discard called discard. Next I am trying to access discard's object called d and then access d's object called playingDeck and using playingDeck's function called createDeck().

I get an error:
 
controller.cpp:534: error: 'class discard' has no member named 'd'


The codes:
http://screensnapr.com/v/5Yo9t4.png

What is wrong? Am I suppose to make a constructor for discard in the .cpp file?
discard has no member d because you have comment it out. Member variables go inside the class definition. Get rid of line 11 and 12 in discard.cpp.
Are we suppose to create objects in the header file and not the cpp file?

I am getting a new error:
deck.h:5: error: redefinition of 'class deck'
deck.h:5: error: previous definition of 'class deck'
handIdentity.h:6: error: redefinition of 'class handIdentity'
handIdentity.h:6: error: previous definition of 'class handIdentity'

My code is below:
handIdentity.cpp
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
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include "deck.h"
#include "handIdentity.h"
using namespace std;

	string computerHand[5];
	string playerHand[5];
	//deck playingDeck;

int handIdentity::sortHand(string hand[5]){
    string temp[5]; //Replica of hand
    int intHandWithoutSuit[5]; //Contains the hand without the suit in integer form
    string stringHandWithoutSuit[5]; //Contains the hand without the suit in string form
    int originalCompareCard;
    int lowestCard;
    int sortedHand[5];
    string finalHand[5];

    for(int i=0; i<5; i++){ //Transfers the hand into the temp
        temp[i]=hand[i];
    }

    for(int j=0; j<5; j++){ //Goes through every card
        string a=temp[j]; //Holds current card
        string b; //Will hold current card w/o suit

        for(unsigned int k=0; k<a.length()-1; k++){ //Removes suit from card and places into b
            b+=a[k];
        }

        stringHandWithoutSuit[j]=b;

        //Goes through cards and replaces J Q K A with 11 12 13 14
        if(b=="J"){
            b="11";
        } else if(b=="Q"){
            b="12";
        } else if(b=="K"){
            b="13";
        } else if(b=="A"){
            b="14";
        }

        //Changes all the strings into integers and stores them into cardWithoutSuit
        istringstream buffer(b);
        int cardWithoutSuit;
        buffer >> cardWithoutSuit;
        intHandWithoutSuit[j]=cardWithoutSuit; //Places cardWithoutSuit into intHandWithoutSuit array
    }

    for(int l=0; l<5; l++){ //Goes through the hand
        if(intHandWithoutSuit[l]!=0){ //Makes sure card is not NULL before continuing
            originalCompareCard=intHandWithoutSuit[l];
            lowestCard=intHandWithoutSuit[l]; //Makes first card the lowest
            int lowestCardPos=l; //Keeps track of its position
            for(int m=0; m<5; m++){ //Compares it to the rest of hand
                if(m!=l){ //If card being compared is not the card being compared to, continue
                    if(intHandWithoutSuit[m]<lowestCard && intHandWithoutSuit[m]!=0){ //Checks if card is lower and not 0=NULL
                        //int temp;
                        lowestCard=intHandWithoutSuit[m]; //Replaces lowestCard value
                        lowestCardPos=m; //Keeps track of position
                    }
                }
            }
            if(lowestCard!=originalCompareCard){
                intHandWithoutSuit[l]=lowestCard;
                intHandWithoutSuit[lowestCardPos]=originalCompareCard;
            }
            intHandWithoutSuit[l]=0; //Changes the lowest card to NULL
        }
        sortedHand[l]=lowestCard;
    }

    for(int n=0; n<5; n++){ //Changes 11 12 13 14 back to J Q K A
        if(sortedHand[n]==11){
            finalHand[n]="J";
        } else if(sortedHand[n]==12){
            finalHand[n]="Q";
        } else if(sortedHand[n]==13){
            finalHand[n]="K";
        } else if(sortedHand[n]==14){
            finalHand[n]="A";
        } else{
            std::ostringstream osstream;
            osstream << sortedHand[n];
            std:: string x = osstream.str();
            finalHand[n] = x;
        }
        //cout << "This is string at finalHand[0][n] is " << finalHand[0][n] << endl;
    }

    for(int o=0; o<5; o++){
        for(int p=0; p<5; p++){
            if(finalHand[o]==stringHandWithoutSuit[p]){
                hand[o]=temp[p];
                stringHandWithoutSuit[p]="99"; // <-- FIX THIS
                break;
            }
        }
    }

    return 0;
}

int handIdentity::searchHandForEmptyCards(string hand[5]){
    string temp[5];

    for(int i=0; i<5; i++){
        temp[i]=hand[i];
    }

    for(int j=0; j<5; j++){
        if(temp[j]==" "){
            hand[j]=playingDeck.drawCard();
        }
    }

    sortHand(hand);

    return 0;
}

handIdentity.h
1
2
3
4
5
6
7
8
9
10
11
12
#include "deck.h"

class handIdentity{
	public:
		std::string computerHand[5];
		std::string playerHand[5];
		deck playingDeck;

	int sortHand(std::string hand[5]);
	int searchHandForEmptyCards(std::string hand[5]);
};

deck.cpp
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
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <ctime>
#include <time.h>
#include "deck.h"
using namespace std;

		string deck[2][52];
int deck::createDeck(){ //Use this to put the cards into the deck...
	for(int i=0; i<52; i++){
		std::ostringstream osstream;
		osstream << i;
		std::string x = osstream.str();

		deck[0][i]="1"; //Available? 1=yes 0=no
	}

	int a=0;
	int sets=1;
	string number="2";

	while(sets<=13){

		for(int j=0; j<52; j++){
			string suit;
			string card;

			if(j==a){
				suit="D";
				card=number+suit;
				deck[1][j]=card;
				suit="C";
				card=number+suit;
				deck[1][j+1]=card;
				suit="H";
				card=number+suit;
				deck[1][j+2]=card;
				suit="S";
				card=number+suit;
				deck[1][j+3]=card;

				switch (sets){
                    case 1:
                        number="3";
                        break;
                    case 2:
                        number="4";
                        break;
                    case 3:
                        number="5";
                        break;
                    case 4:
                        number="6";
                        break;
                    case 5:
                        number="7";
                        break;
                    case 6:
                        number="8";
                        break;
                    case 7:
                        number="9";
                        break;
                    case 8:
                        number="10";
                        break;
                    case 9:
                        number="J";
                        break;
                    case 10:
                        number="Q";
                        break;
                    case 11:
                        number="K";
                        break;
                    case 12:
                        number="A";
                        break;
                    default:
                        number="2";
                        break;
                }
			}

		}
		a+=4;
		sets++;
	}
	return 0;
}

int deck::checkAvailabilty(int cardIndex){ //Checks if card is in deck
    if(deck[0][cardIndex]=="1"){ //If it is, it returns a 1
        return 1;
    } else{ //If not, it returns a 0
        return 0;
    }
}

string deck::cardIdentity(int cardIndex){
    return deck[1][cardIndex];
}

void deck::removeCard(int cardIndex){
    deck[0][cardIndex]="0";
}

string deck::drawCard(){
    srand ( time(NULL) );
    int random = rand()%52;
    while(checkAvailabilty(random)==0){
        random = rand()%52;
    }
    removeCard(random);
    return cardIdentity(random);

}

deck.h
1
2
3
4
5
6
7
8
9
10
11
class deck{
	public:
		std::string deck[2][52];

	int createDeck();
	int checkAvailabilty(int cardIndex);
	std::string cardIdentity(int cardIndex);
	void removeCard(int cardIndex);
	std::string drawCard();
};
Solved it.
Topic archived. No new replies allowed.