Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Private container, public iterator

Reply
Thread Tools

Private container, public iterator

 
 
quantdev2004@yahoo.co.uk
Guest
Posts: n/a
 
      03-17-2005
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

 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      03-17-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments