Rolf said:
Dpends on how you do it currently.
All right, the header file looks like this:
======================================================================
#define _Hand_H_
#include "Card.h"
class Hand {
public:
Hand();
bool add(Card prmCard);
bool canDouble();
bool canSplit();
int getSize();
int getValue();
bool isBlackjack();
bool isBusted();
bool isSoft();
void setHidden(int prmHideNo);
private:
bool clsSoft;
int clsCount;
int clsHidden;
Card clsCard[10];
};
======================================================================
The body looks like this:
======================================================================
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
// Declarations...
#ifndef _Hand_H_
#include "Hand.h"
#endif
// Definitions...
bool clsSoft = false;
int clsCount = 0;
int clsHidden = 0;
Card clsCard[10];
// Constructors...
Hand::Hand( ) {
}
// Methods...
bool add(Card prmCard) {
clsCard[clsCount++] = prmCard;
};
bool canDouble() {
bool tmpBool = false;
int tmpVal = this->getValue( ); <-- This line fails
if ( clsCount == 2
&& (tmpVal == 10 || tmpVal == 11)
)
tmpBool = true;
return tmpBool;
};
bool canSplit() {
;
};
int getSize() {
return clsCount;
};
int getValue() {
int sumInt = 0;
bool thereBeAcesHere = false;
for ( int h = 0; h < clsCount; h++) {
int tmpInt = clsCard[h].getFaceValue();
sumInt += tmpInt;
if (tmpInt==1) thereBeAcesHere = true;
}
clsSoft = false;
if (thereBeAcesHere && sumInt < 12) {
sumInt += 10;
clsSoft = true;
}
return sumInt;
};
bool isBlackjack() {
;
};
bool isBusted() {
;
};
bool isSoft() {
;
};
void setHidden(int prmHideNo) {
clsHidden = prmHideNo;
};
======================================================================
The error I get is "invalid use of `this' in non-member function,"
which, as far as I know, is a member function. But I'm sure that I'm
missing something obvious here.
virtual is only needed for polymorphism.
That's what I thought too.
But then, that's why I'm asking questions,
cause I'm not sure what the issue is.
Ed.