How to name comparison predicate function to sort vector
<p>I'm a beginner at C++ and have a question regarding sorting a vector of a class object.  I've done a lot of research online but can't seem to figure out the answer.  My problem is that I want to have multiple predicate comparison functions that I can name, as I need to have the user be able to choose from a menu which private member variable/component of the vector to sort on.  I'm able to get a predicate comparison function with an overloaded operator to work ok, but when I try and name the function, I can't seem to get it to compile without a bunch of errors (which I'll post farther down underneath the appropriate code).</p>

<p>When the code's run, a vector of a BookData object is created by a function that reads a text file.  Function prototype in main:</p>

<pre><code>vector&lt;BookData&gt; createVector();
</code></pre>

<p>Function call in main:</p>

<pre><code>vector&lt;BookData&gt; books = createVector();
</code></pre>

<p>createVector function definition:</p>

<pre><code>vector&lt;BookData&gt; createVector()
{
    const int LENGTH = 81;
    char input[LENGTH];
    vector&lt;BookData&gt; fBooks;
    string vBookTitle, vIsbn, vAuthor, vPublisher, vDateAdded;
    int vQtyOnHand;
    double vWholesale, vRetail;
    BookData *books1;
    books1 = new BookData;
    fstream dataFile("Serendipity.data");
    if (dataFile.is_open())
    {
        while (!dataFile.eof())
        {
            dataFile.getline(input, LENGTH, '\t');
            vBookTitle = input;
            books1-&gt;setTitle(vBookTitle);
            dataFile.getline(input, LENGTH, '\t');
            vAuthor = input;
            books1-&gt;setAuthor(vAuthor);
            dataFile.getline(input, LENGTH, '\t');
            vPublisher = input;
            books1-&gt;setPub(vPublisher);
            dataFile.getline(input, LENGTH, '\t');
            vIsbn = input;
            books1-&gt;setIsbn(vIsbn);
            dataFile &gt;&gt; vQtyOnHand;
            books1-&gt;setQty(vQtyOnHand);
            dataFile &gt;&gt; vWholesale;
            books1-&gt;setWholesale(vWholesale);
            dataFile &gt;&gt; vRetail;
            books1-&gt;setRetail(vRetail);
            dataFile.ignore();
            dataFile.getline(input, LENGTH);
            vDateAdded = input;
            books1-&gt;setDateAdded(vDateAdded);
            fBooks.push_back(*books1);
        }
    }
    return fBooks;
}
</code></pre>

<p>This is my class definition file (bookdata.h) with the working comparison function:</p>

<pre><code>class BookData
{ 
private:
        string bookTitle, isbn, author,
            publisher, dateAdded;
        int qtyOnHand;
        double wholesale, retail;
        bool empty;     

public:
    BookData();
    bool operator&lt; (BookData rhs);
    void printVector();
    void setTitle(string);
    void setIsbn(string);
    void setAuthor(string);
    void setPub(string);
    void setDateAdded(string);
    void setQty(int);
    void setWholesale(double);
    void setRetail(double);
    int isEmpty();
    void insertBook();
    void removeBook();
    string getTitle();
    string getIsbn();
    string getAuthor();
    string getPublisher();
    string getDateAdded();
    int getQtyOnHand();
    double getWholesale();
    double getRetail();
};
</code></pre>

<p>And this is the working function in the class implementation file (bookdata.cpp):</p>

<pre><code>bool BookData::operator&lt; (BookData rhs)
{
    return qtyOnHand &lt; rhs.qtyOnHand;
}
</code></pre>

<p>And it's called like so from int main():</p>

<pre><code>sort (books.begin(), books.end());
</code></pre>

<p>However, if I try and name the function:</p>

<pre><code>bool compare (BookData rhs);
</code></pre>

<p>from within the class definition file and change it to this in the class implementation file:</p>

<pre><code>bool BookData::compare (BookData rhs)
{
    return qtyOnHand &lt; rhs.qtyOnHand;
}
</code></pre>

<p>and change the vector sort function so within main:</p>

<pre><code>sort (books.begin(), books.end(), &amp;BookData::compare);
</code></pre>

<p>I get an error message from the compiler:</p>

<p>error C2064: term does not evaluate to a function taking 2 arguments</p>

<p>Any suggestions as to how I can properly name/call the sort function?</p>
