By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

Singleton Null Reference Exception

P: n/a
hi,

I have a singleton class called 'Evaluation' which is a utility class
used to determine the strength of a poker hand. two members of
'Evaluation' are highCard and lowCard, two objects of user-defined
class Card.

for some reason I am having null reference problems at the bottom of
the function excerpt shown below:

int Evaluation::AppraiseHoleCards(Hand targetHand)
{
const int regularPairBonus = 3;
const int sameSuitBonus = 3;
const int lowJackBonus = 5;
const int lowQueenBonus = 7;
const int lowKingBonus = 9;
const int facePairBonusFactor = 2;
// potential bonuses in order of increasing significance

int holeCardsStrength = 0;
vector<Card> tempVector(targetHand.GetHoleCards());

SortCardVector(tempVector);

highCard = tempVector.back();
lowCard = tempVector.front();

GetHoleCards() returns the vector of (two) Card objects contained in
targetHand.

basically I am using a for loop to put all hands in the game through
the function above, which I call like this:
Evaluation::Instance().AppraiseHoleCards(targetPla yer.GetHand())

what happens is the first hand is evaluated normally but the program
crashes on the second hand, citing a Null Reference Exception at the
lines

highCard = tempVector.back();
lowCard = tempVector.front();

anyone see what I'm doing wrong?

thx a lot

Nov 28 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
A_*********@hotmail.com wrote:
hi,

I have a singleton class called 'Evaluation' which is a utility class
used to determine the strength of a poker hand. two members of
'Evaluation' are highCard and lowCard, two objects of user-defined
class Card.

for some reason I am having null reference problems at the bottom of
the function excerpt shown below:

int Evaluation::AppraiseHoleCards(Hand targetHand)
{
const int regularPairBonus = 3;
const int sameSuitBonus = 3;
const int lowJackBonus = 5;
const int lowQueenBonus = 7;
const int lowKingBonus = 9;
const int facePairBonusFactor = 2;
// potential bonuses in order of increasing significance

int holeCardsStrength = 0;
vector<Card> tempVector(targetHand.GetHoleCards());

SortCardVector(tempVector);

highCard = tempVector.back();
lowCard = tempVector.front();

GetHoleCards() returns the vector of (two) Card objects contained in
targetHand.

basically I am using a for loop to put all hands in the game through
the function above, which I call like this:
Evaluation::Instance().AppraiseHoleCards(targetPla yer.GetHand())

what happens is the first hand is evaluated normally but the program
crashes on the second hand, citing a Null Reference Exception at the
lines

highCard = tempVector.back();
lowCard = tempVector.front();

anyone see what I'm doing wrong?


Check the size of "tempVector". It is possible that the vector does not
have any values.

You think "SortCardVector(tempVector);" has got anything to do with
this ?

Nov 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.