473,513 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A list of reference?

Derived1 and Derived2 are derived from BaseClass:

list<BaseClass&> lst;
Derived1 d1;
Derived2 d2;
lst.push_back(d1);
lst.push_back(d2);

Can a list be created like above so that d1, d2... objects can be navigated
to?

I read somewhere "A list container should not contain a list of references
since they are not assignable." What does this mean? Thanks!
Jul 22 '05 #1
2 1277

"foggy" <fo***@turboweb.com> wrote in message
news:AA*******************@bgtnsc05-news.ops.worldnet.att.net...
Derived1 and Derived2 are derived from BaseClass:

list<BaseClass&> lst;
Derived1 d1;
Derived2 d2;
lst.push_back(d1);
lst.push_back(d2);

Can a list be created like above so that d1, d2... objects can be navigated to?
No, use pointers instead.

I read somewhere "A list container should not contain a list of references
since they are not assignable." What does this mean? Thanks!


Err, exactly what it says (except I would say 'cannot' not 'should not').
Lists make some assumptions on the objects they contain, one of which is
that the objects themselves can be assigned. References cannot be assigned

int a = 1;
int b = 2;
int& r = a;
r = b;

r = b does not assign to the reference, it assigns the value of b to a, r
still refers to a.

john
Jul 22 '05 #2
"foggy" <fo***@turboweb.com> wrote in message news:<AA*******************@bgtnsc05-news.ops.worldnet.att.net>...
Derived1 and Derived2 are derived from BaseClass:

list<BaseClass&> lst;
Derived1 d1;
Derived2 d2;
lst.push_back(d1);
lst.push_back(d2);

Can a list be created like above so that d1, d2... objects can be navigated
to?


Use boost::reference_wrapper<BaseClass> instead of BaseClass&.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7936
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value'...
1
2501
by: John Hunter | last post by:
I am writing a python extension module and have a reference counting question My function looks like static PyObject * pokereval_seven_cards(PyObject *self, PyObject *args) { int i;
1
9996
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list...
14
5589
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
8
2827
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
8
420
by: source | last post by:
a function that would: return the 5th element from the end in a singly linked list of integers, in one pass, and then provide a set of test cases against that function. Can we do this in CSharp?...
45
18765
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
10
6553
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
7
2802
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
7
5756
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.