Solved

Vector of references?

Posted on 2008-10-09
2
616 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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++.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now