 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
A_StClaire_@hotmail.com Guest
|
Posted: Mon Nov 28, 2005 1:04 am Post subject: Singleton Null Reference Exception |
|
|
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
|
|
| Back to top |
|
 |
Sandeep Guest
|
Posted: Mon Nov 28, 2005 2:56 am Post subject: Re: Singleton Null Reference Exception |
|
|
[email]A_StClaire_ (AT) hotmail (DOT) com[/email] wrote:
| Quote: | 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 ?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|