GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Oct-2004, 10:07
wc3promet wc3promet is offline
New Member
 
Join Date: Oct 2004
Posts: 7
wc3promet is on a distinguished road

How do I check whether the object q1 exists? ie: q1=new queue has been called?


How do I check whether the object q1 exists? ie: q1=new queue has been called?

In Main
CPP / C++ / C Code:
queue* q1;

Partial Body of Menu Code
CPP / C++ / C Code:
  	case 1:
	 cout<<"\n";
 	q1 = new queue;
 	break;

Partial Body of Enqueue Code
CPP / C++ / C Code:
str name;
name = "Some Name"
q1->enqueue(name);

Because if I call the enqueue(), the program is going to crash. Testing whether q1==NULL doesn't seem to help.

Any suggestions? Thanks.
  #2  
Old 15-Oct-2004, 10:15
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi. Why don't you set it to NULL when you define it?

CPP / C++ / C Code:
queue* q1 = NULL;

That should point the pointer to 0 (undefined). Then you should be able to test whether it is there by:

CPP / C++ / C Code:
if(q1){
}
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:04.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.