CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #1
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Resolved Custom (readonly) container and iterators ?

    I'm working on writing some classes around a ROM hardware addon card. The classes expose the data on the ROM as a container with iterators, much like a vector or a list.

    The classes don't have any data themselves, since all the data is on the ROM.

    I'm having some dillemma's as to how to approach/implement the classes. If you were to write somethign like this... Or were using something like this written by someone else.... How would you expect this to be done ?

    1)
    Make all the member functions static, make a private constructor to prevent making instances.
    This works, but may look a bit weird...
    Code:
       for (auto it = RomTable::begin(); it != RomTable::end(); ++it)
    2)
    expect users to make a (dummy) instance, then use it as a regular container.
    this might be a bit counter intuitive since the class has no datamembers.

    3)
    create a single instance, expect users to use that everywhere. make the constructor inaccessible.
    Some C++ 'purists' might perceive this as global data and thus not a good solution ?

    4) Somethign else entirely ?



    --

    Additionally. Do I need to provide both a const_iterator and an iterator ? There's nothing to be modified, so I'm guessing an iterator isn't needed (?) Or will some STL stuff not work without an iterator ? I'm obviously not fussed about the STL functions that make changes to the container to not work (like sort, fill, swap...)
    Last edited by OReubens; July 8th, 2012 at 12:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured