473,466 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Private container, public iterator

Dear NG,

I have seen this code and was wondering about its meaning:

class MyClass
{

private:
typedef stl::hash_map<stl::string,
int,
FHashTraitsStringNoCase> string_2_int;

string_2_int m_String2Int;
public:

typedef string_2_int::const_iterator string_2_int_const_iterator;

// Iterate over the string_2_int
string_2_int_const_iterator BeginStringInt() const
{
return m_String2Int.begin();
}
}
The meaning of this puzzles me. What is this achieving? Hiding the
string_2_int type, but declaring an iterator to that same type to be
public, does not look like it's encapsulating anything.

Can someone please expand a bit on what is exactly happening and why
would one want to choose this approach?

Thanks,
QD

Jul 23 '05 #1
1 1462
qu**********@yahoo.co.uk wrote:

The meaning of this puzzles me. What is this achieving? Hiding the
string_2_int type, but declaring an iterator to that same type to be
public, does not look like it's encapsulating anything.
Especially since the exposed name of the type is
string_2_int_const_iterator. The convention throughout the STL is that
containers have typedefs named 'iterator, 'const_iterator', etc.

Can someone please expand a bit on what is exactly happening and why
would one want to choose this approach?


Aside from the naming issues, what it does is provide a sequence
delineated by a pair of iterators. That sequence can be operated on by
STL algorithms. This is done without exposing the details of how the
sequence is stored.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #2

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

Similar topics

8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
8
by: Aman | last post by:
does it matter if a typedef is declared under public or private ? does any one (public or private ) constitute better design ? -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
11
by: Vivi Orunitia | last post by:
Hi all, I tried looking this up in the sgi docs but it didn't provide any concrete answer to what I'm looking for. Basically, is there any difference between using ::iterator for a container vs...
41
by: AngleWyrm | last post by:
I have created a new container class, called the hat. It provides random selection of user objects, both with and without replacement, with non-uniform probabilities. Uniform probabilities are a...
0
by: nick | last post by:
Hi, I need to manage a "layered" collection of objects, where each layer grows independently, e.g, o--+--+--+--+--+ 1st layer | o 2nd layer (empty) | o--+--+--+ 3rd...
14
by: PengYu.UT | last post by:
In the following program, I want an iterator contain pointer pointing to constant object not const pointer. If it is possible would you please let me know how to do it? #include...
1
by: swhite | last post by:
Hi, Sorry, not very clear from the title but wasn't sure what to call it. I was experimenting with the following in GCC 4.0.1 and didn't achieve what I expected. I was trying to keep the...
16
by: arnaudk | last post by:
I'm trying to design a simple container class for some data of different types based on a vector of structs, but the vector and struct are protected so that the implemenation of my container class...
7
by: Leslie Sanford | last post by:
My area of programming is DSP. I write things like filters, oscillators, envelopes, etc. I've been looking at STL iterators, and what's struck me is that if I can find ways to model my code using...
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
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
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...
1
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
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.