473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

using a custom class in a list

What do I have to do in order to create a list of one of my own classes?
That is, in order for:

list<myClass> myList;

to be a valid statement. I know I might have to define an iterator on it,
or implement operators like ++, but I don't know the details. Can anyone
let me know, or point to a good reference on the web?

Thanks,
cppaddict
Jul 19 '05 #1
2 3524
"cppaddict" <cp*******@yahoo.com> wrote...
What do I have to do in order to create a list of one of my own classes?
That is, in order for:

list<myClass> myList;

to be a valid statement. I know I might have to define an iterator on it,
or implement operators like ++, but I don't know the details. Can anyone
let me know, or point to a good reference on the web?


You need to

a) Include the <list> header
b) Declare std::list so that it could be named 'list' (no std::)
c) Make sure your 'myClass' is
1) Assignable
2) Copy-constructible

Victor
Jul 19 '05 #2
> What do I have to do in order to create a list of one of my own
classes? That is, in order for:

list<myClass> myList;

to be a valid statement.
Only the name 'myClass' defined :

# include <list>

class myClass
{
};

int main()
{
std::list<myClass> myList;
}

And that's it (try it).
I know I might have to define an iterator
on it, or implement operators like ++, but I don't know the details.
God, no!! That's why there is a library already written for you.

Iterators do not depend on the contained object, but on the container.
Operators concerning that iterator are defined by that iterator, no by you.
Can anyone let me know, or point to a good reference on the web?


Concerning the standard library, get "The C++ Standard Library" by Josuttis.
Jonathan

Jul 19 '05 #3

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

Similar topics

12
by: Brian Genisio | last post by:
Hi all, I am developing some software, that creates a tree of information. For each node, currently I am overriding the new operator, because it is a requirement that after initialization, no...
0
by: Eric Dreksler | last post by:
Hi, I'm trying to make a custom implementation of ListControl, where I pass in a control type (based off a MustInherit UserControl) and a DataSource. Public Class PrettyControlList Inherits...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
5
by: Mountain | last post by:
I'm working with the example code found at http://msdn2.microsoft.com/en-us/library/system.configuration.applicationsettingsbase(VS.80).aspx. I would like to implement application settings based...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
2
by: filipk69 | last post by:
Could someone point me in the right direction, please. I have an enum something like this: enum TextFieldType { FieldABC = 3000, FieldXYZ = 3001, ….. ….. }
6
by: Bryan | last post by:
I am writing a class that has a list of strings as one of its properties. I want to be able to run some code whenever that list of strings is modified through the class property. Here is the...
0
by: =?Utf-8?B?RnV0cm9uaWNzIERldmVsb3Blcg==?= | last post by:
I am trying to store a collection of custom types in a Properties.Settings file which I will be updating at run time and saving on exit of the program. I understand how to use the...
2
by: | last post by:
I am using a datareader to cycle through a list of records one at a time. I frequently get connection timeouts and am wondering what I am doing wrong. In more detail, I retrieve an excel...
0
by: jappenzeller | last post by:
I've got a coding standard question for generic lists and .NET 2.0. I have created some custom strongly typed lists like, MyClassList:List<MyClass>. We did this because we wanted to reuse some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.