473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(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
1 1817
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marty McDonald | last post by:
public static object GetInstance(Type type, object args) { object o = _hashObjects; if (o == null) { lock (_hashObjects) { //Still null? Need to check again because someone may //have added...
13
by: William Stacey | last post by:
FYI. /// <summary> /// Author: William Stacey /// Fast and simple way to implement a singleton pattern without resorting /// to nested classes or other static vodo. Can also be easily converted...
7
by: Stephen Brown | last post by:
I have some strange behavior on my web server that seems to point to garbage collection. I have a singleton that tracks web activity on my web site. The singleton works great, except that it...
14
by: Paul Bromley | last post by:
Forgive my ignorance on this one as I am trying to use a Singleton class. I need to use this to have one instance of my Class running and I think I understand how to do this. My question however is...
7
by: PMarino | last post by:
Hi all - I've taken some code from MSDN and made a Generic singleton, so that I don't have to write this code in many places: public class Singleton<TEntity> where TEntity : class, new() {...
2
by: Michel van den Berg | last post by:
Hello, I tried to implement the GoF Singleton Pattern. What do you think? Public MustInherit Class Singleton(Of T As New) Public Sub New() If SingletonCreator.Creating = False Then Throw...
7
by: John A Grandy | last post by:
For a singleton class utilizes by ASP.NET 2.0 page processing: When initial instantiation is performed during the initial call to the retrieve instance method (let's call the method...
5
by: tobias.sturn | last post by:
Hi! I have written this template for making a singleton: #define DECLARE_SINGLETON(classname) \ private: \ static classname* m_pThis; \ classname(); \ class Guard \ { \ public: \
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.