• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

Vector of references?

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
nanderEire
Asked:
nanderEire
  • 2
1 Solution
 
Infinity08Commented:
>> 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
 
Infinity08Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now