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

Thread: operator*

  1. #1
    Join Date
    May 2000
    Location
    Germany
    Posts
    369

    operator*

    Hello!
    I have a general question. When i define an iterator what do the operator * have to return. For example: If i want to implement a string iterator like this...
    Code:
    template<class C>
    class StringIt : public iterator<...>
    {
    
    };
    What does the iterator-class have to return when i invoke the operator *. Must it be the element of the container ( in this example a reference of a char ) or something else? What do i have to use for the second template parameter for the inherited class iterator?

    thanks

  2. #2
    Join Date
    Sep 2002
    Posts
    1,747

    since its your iterator...

    You can return anything you like. Its often helpful to return the actual dereference of the iterator's pointee, something like
    Code:
    template <class MyStringObjectType>
    class Iterator
    {
    public:
         // ... whatever else goes here
         MyStringObjectType& operator*() const
         {
              // ... maybe you want to do something here
              return *pointee_;
         }
    private:
         MyStringObjectType* pointee_;
    };
    In this case use the class for your iterator's template parameter. I hope this helps you...
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

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