iterating over a set of pointers
<p>In my current project, I have the following type of set:</p>

<pre><code>typedef set&lt;ItemPtr&gt;            ItemSet;
</code></pre>

<p>where ItemPtr is this class:</p>

<pre><code>class ItemPtr
{
    private:
    Item    *ptr;

    public:
    ItemPtr(Item *ptr) : ptr(ptr) { }
    Item* getPtr() const { return ptr; }
};
</code></pre>

<p>And the following sets:</p>

<pre><code>ItemSet bookList;
ItemSet movieList;
ItemSet musicAlbumList;
</code></pre>

<p>Which are all sets contained in a class called Library.  Each of these sets contain instances of ItemPtr, where each instance of ItemPtr contains a pointer to to an instance of Book, Movie, or MusicAlbum.  Each of these are derived classes from a class called Item.  An instance of Book, contains an author, title, number of Pages, and a set of keywords that are common to that book.  I have a function as such:</p>

<pre><code>const ItemSet* Library::itemsForKeyword(const string&amp; keyword)
{
    return NULL;  //need to put code in here
}
</code></pre>

<p>that needs to return all items from each set that have the parameter in its list of keywords.  I am unsure how to iterate through each set, and access it's keywords, then compare them to the parameter of the above function.  How can I do such a comparison?</p>

<p>Here is my Item class:</p>

<pre><code>class Item
{
    public:
    string mTitle;
    string mArtist;
    Item(const string&amp; title, const string&amp; artist);
    Item();
    virtual ostream &amp;print(std::ostream &amp;os) const
    {
        os &lt;&lt; "author: \t" &lt;&lt; mArtist &lt;&lt; endl;
        os &lt;&lt; "title: \t" &lt;&lt; mTitle &lt;&lt; endl;
        return os;
    }
    virtual ~Item();
    set&lt;string&gt;  keywordsList;
    void addKeywords(string keyword);
};
</code></pre>

<p>This is the addKeywords function:</p>

<pre><code>void Item::addKeywords(string keyword)
{
keywordsList.insert(keyword);
}
</code></pre>

<p>And here is as far as I've gotten thus far on writing the function I need:</p>

<pre><code>const ItemSet* Library::itemsForKeyword(const string&amp; keyword)
{
ItemSet temp;

for(it=bookList.begin();it!=bookList.end();it++){
    if(it-&gt;getPtr()-&gt;keywordsList)


}

return &amp;temp;
}
</code></pre>

<p>I know that by referencing getPtr with my iterator, it gives me access to keywordsList, but from that point I don't know how to examine the list to compare it to the passed in keyword.  My plan is to, after comparing and finding a match, store the instance in temp, then pass back temp with all the items that contained that keyword. Thanks for the help thus far.</p>
