472,352 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 1424
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...
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...
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...
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...
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 ...
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...
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...
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...
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...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.