Help my member function return a string.

I need to know how to return the right data type for this class.
I guessed that I create an array and return a string.
I am having trouble with getCardCode()in my (.cpp)

if you need more I have my header file and main I can post to make the problem clear.

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
#include "PlayingCard.h"
#include <string>



std::string PlayingCard::getCardCode()
{
    char codeVal[] = {'X', 'A', 2, 3, 4, 5, 6, 7, 8, 9, 'T', 'J', 'Q', 'K'};
    char codeSuit[] = {'S', 'C', 'D', 'H'};
    std::string code[] = {codeVal, codeSuit};

    return code[2]();
}
bool PlayingCard::setCard(char myValue, char mySuit)
{
if((mySuit == 'S' || mySuit == 'C' || mySuit == 'D' || mySuit == 'H') && (myValue >= 2 || myValue <= 9 || myValue == 'A' || myValue == 'T' || myValue == 'J' || myValue == 'Q' || myValue == 'K'))
    return true;
else
    return false;
}
bool PlayingCard::isValid()
{
char Value = value, Suit = suit;
if((Value >=2 || Value <=9 || Value == 'A' || Value == 'T' || Value == 'J' || Value == 'Q' || Value == 'K') && (Suit == 'S' || Suit == 'C' || Suit == 'D' || Suit == 'H'))
    return true;
else
    return false;
}
PlayingCard::~PlayingCard()
{
    //dtor
}
Explain what exactly lines 8 - 12 are supposed to do.
I'm not sure what that function is supposed to do? Without looking at the return, it could also be written like this if you do not give values to anything.
1
2
3
char codeVal[14];
char codeSuit[4];
string code[codeVal][codeSuit];


Or at least that is what it looks like you are trying to do. I think what you want is something more like this"
1
2
3
4
5
std::string PlayingCard::getCardCode(int val, int suit)
{
	// Do stuff
	return code;
}
Topic archived. No new replies allowed.