Solved

Vector of references?

Posted on 2008-10-09
2
620 Views
Last Modified: 2012-06-27
Can I use a vector (or any container) of references? Or must I use pointers?

If not, why not?

std::vector<Object&> vector_of_references;
0
Comment
Question by:nanderEire
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 125 total points
ID: 22679161
>> Can I use a vector (or any container) of references?

No.


>> Or must I use pointers?

That is one option, yes.


>> If not, why not?

References always need to refer to an existing object. You cannot declare a reference without specifying which object it refers to. So, you cannot have a container of references.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22679218
May I ask why you gave a B grade ? That usually means that something was missing in the answer and/or that something is still unclear. If that's the case, then do not hesitate to ask for clarification where needed.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question