C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Singleton Null Reference Exception

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
A_StClaire_@hotmail.com
Guest





PostPosted: Mon Nov 28, 2005 1:04 am    Post subject: Singleton Null Reference Exception Reply with 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?

thx a lot

Back to top
Sandeep
Guest





PostPosted: Mon Nov 28, 2005 2:56 am    Post subject: Re: Singleton Null Reference Exception Reply with quote



[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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.