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 11-Apr-2005, 18:55
mirizar mirizar is offline
New Member
 
Join Date: Jun 2004
Posts: 20
mirizar is on a distinguished road

vectors of references


Hi! I know you can have vectors of values and vectors of pointers, but can you have vectors of references??

Thanks, Michelle
  #2  
Old 12-Apr-2005, 02:02
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,031
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by mirizar
Hi! I know you can have vectors of values and vectors of pointers, but can you have vectors of references??

Thanks, Michelle

No, a reference is just an alias (another name) for your variable. You need to initialise it from the start, and you can't change it to "point" (this is NOT the right word ) to anything else.

CPP / C++ / C Code:
	int i_var = 5;
	int & ri_var = i_var;	

In this sample code, ri_var is just another name for i_var in the current scope.

However, this is illegal:
CPP / C++ / C Code:
	int i_var1 = 5, i_var2 = 6;
	int & ari_var[2] = {i_var1, i_var2};

You can't name i_var1 -> ari_var[0], that would be cumbersome, right?


Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogProblems with the Navy (Officers) 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with vectors iamsodumb C++ Forum 1 18-Mar-2005 15:50
newbie needs help with vectors Quesius C++ Forum 0 30-Nov-2004 23:35
C++ Vectors Katie C++ Forum 5 17-May-2004 23:36
Declaring a vector of vectors? Lethal411 C++ Forum 2 20-Mar-2004 09:02
help with c++ vectors beebop C++ Forum 1 12-Mar-2004 06:03

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

All times are GMT -6. The time now is 02:06.


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