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'
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include "deck.h"
#include "handIdentity.h"
usingnamespace 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(unsignedint 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";
} elseif(b=="Q"){
b="12";
} elseif(b=="K"){
b="13";
} elseif(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";
} elseif(sortedHand[n]==12){
finalHand[n]="Q";
} elseif(sortedHand[n]==13){
finalHand[n]="K";
} elseif(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]);
};