Singleton Null Reference Exception

A

A_StClaire_

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(targetPlayer.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
 
S

Sandeep

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(targetPlayer.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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top