`make` Error that is confusing me...

Discussion in 'C++' started by PekinSOFT@gmail.com, Mar 1, 2008.

  1. Guest

    Hey all,

    I'm working through the book "GUI Programming with Qt3" and have
    worked my way through Chapter 4, creating a small spreadsheet
    application. I'm finally to a point where I can compile the program
    and see how it looks, but I keep get some cryptic error that I don't
    understand. Maybe you all can help me out here.

    I've created many files and have all of them included properly in my
    implementation files, so I know the problem is not there. The error
    that I'm getting is as follows:

    -----------------------------------------------------------------------------------------------------------------------------------
    spreadsheet.h: In member function 'bool Spreadsheet::autoRecalculate()
    const':
    spreadsheet.h:19: error: argument of type 'bool (Spreadsheet::)()'
    does not match 'bool'
    make: *** [mainwindow.o] Error 1

    -----------------------------------------------------------------------------------------------------------------------------------
    The file in question, spreadsheet.h, has the following on line 19:

    bool autoRecalculate() const { return autoRecalc; }

    Now, I don't understand what the compiler is trying to tell me with
    the statement, "argument of type bool (SPreadsheet::)() does not
    match bool". Any help with this is greatly appreciated. Thank you
    all for your time.

    Cheers,

    Sean Carrick
    PekinSOFT Systems
    PekinSOFT at gmail dot com
     
    , Mar 1, 2008
    #1
    1. Advertising

  2. Guest

    <> wrote in message news:
    ...
    > The file in question, spreadsheet.h, has the following on line 19:
    >
    > bool autoRecalculate() const { return autoRecalc; }
    >
    > Now, I don't understand what the compiler is trying to tell me with
    > the statement, "argument of type bool (SPreadsheet::)() does not
    > match bool".


    You didn't give a lot of information so this is a guess.

    Is autoRecalculate() a member function of something? What about
    autoRecalc, what is that? Is it a function? If so the line should be
    this:

    bool autoRecalculate() const { return autoRecalc(); }

    Note the parentheses. That calls autoRecalc() and returns the result,
    rather than returning a function pointer which can't be converted to a
    bool.

    Is autoRecalc a variable? If it is, then your error is from something
    else, you need to give more context.

    Is autoRecalc a macro? If it is, see what it is #defined to. That may
    be causing a problem.

    Jason
     
    , Mar 1, 2008
    #2
    1. Advertising

  3. Guest

    On Mar 1, 10:50 am, ""
    <> wrote:
    > <> wrote in message news:
    >
    > ...
    >
    > > The file in question, spreadsheet.h, has the following on line 19:

    >
    > > bool autoRecalculate() const { return autoRecalc; }

    >
    > > Now, I don't understand what the compiler is trying to tell me with
    > > the statement, "argument of type bool (SPreadsheet::)() does not
    > > match bool".

    >
    > You didn't give a lot of information so this is a guess.
    >
    > Is autoRecalculate() a member function of something? What about
    > autoRecalc, what is that? Is it a function? If so the line should be
    > this:
    >
    > bool autoRecalculate() const { return autoRecalc(); }
    >
    > Note the parentheses. That calls autoRecalc() and returns the result,
    > rather than returning a function pointer which can't be converted to a
    > bool.
    >
    > Is autoRecalc a variable? If it is, then your error is from something
    > else, you need to give more context.
    >
    > Is autoRecalc a macro? If it is, see what it is #defined to. That may
    > be causing a problem.
    >
    > Jason


    Jason,

    Thanks for your quick reply. I am pasting the spreadsheet.h and
    spreadsheet.cpp files below for your review. `autoRecalculate` is a
    member function and `autoRecalc` is a variable. See what you can make
    from the files below...I probably have a stupid typo that I'm
    missing...

    ------------------------------------------------
    Begin file: spreadsheet.h
    ------------------------------------------------
    #ifndef SPREADSHEET_H
    #define SPREADSHEET_H

    #include <qstringlist.h>
    #include <qtable.h>

    class Cell;
    class SpreadsheetCompare;

    class Spreadsheet : public QTable
    {
    Q_OBJECT
    public:
    Spreadsheet(QWidget *parent = 0, const char *name = 0);

    void clear();
    QString currentLocation() const;
    QString currentFormula() const;
    bool autoRecalculate() const { return autoRecalc; }
    bool readFile(const QString &fileName);
    bool writeFile(const QString &fileName);
    QTableSelection selection();
    void sort(const SpreadsheetCompare &compare);

    public slots:
    void cut();
    void copy();
    void past();
    void del();
    void selectRow();
    void selectColumn();
    void selectAll();
    void recalculate();
    void setAutoRecalculate(bool on);
    void findNext(const QString &str, bool caseSensitive);
    void findPrev(const QString &str, bool caseSensitive);

    signals:
    void modified();

    protected:
    QWidget *createEditor(int row, int col, bool initFromCell) const;
    void endEdit(int row, int col, bool Accepted, bool wasReplacing);

    private:
    enum { MagicNumber = 0x7F51C882, NumRows = 999, NumCols = 26 };

    Cell *cell(int row, int col) const;
    void setFormula(int row, int col, const QString &formula);
    QString formula(int row, int col) const;
    void somethingChanged();

    bool autoRecalc();
    }; // End of Spreadsheet class definition.

    class SpreadsheetCompare
    {
    public:
    bool operator()(const QStringList &row1,
    const QStringList &row2) const;

    enum { NumKeys = 3 };
    int keys[NumKeys];
    bool ascending[NumKeys];
    }; // End of SpreadsheetCompare class definition.

    #endif
    ------------------------------------------------
    End of file: spreadsheet.h
    ------------------------------------------------

    ------------------------------------------------
    Begin file: spreadsheet.cpp
    ------------------------------------------------
    #include <qapplication.h>
    #include <qclipboard.h>
    #include <qdatastream.h>
    #include <qfile.h>
    #include <qlineedit.h>
    #include <qmessagebox.h>
    #include <qregexp.h>
    #include <qvariant.h>

    #include <algorithm>
    #include <vector>
    using namespace std;

    #include "cell.h"
    #include "spreadsheet.h"

    Spreadsheet::Spreadsheet(QWidget *parent, const char *name)
    : QTable(parent, name)
    {
    autoRecalc = true;
    setSelectionMode(Single);
    clear();
    } // End of Spreadsheet class constructor.

    void Spreadsheet::clear()
    {
    setNumRows(0);
    setNumCols(0);
    setNumRows(NumRows);
    setNumCols(NumCols);
    for (int i = 0; i < NumCols; i++)
    horizontalHeader()->setLabel(i, QChar('A' + i));
    setCurrentCell(0, 0);
    } // End of Spreadsheet::clear() public function.

    Cell *Spreadsheet::cell(int row, int col) const
    {
    return (cell *)item(row, col);
    } //Eend of Spreadsheet::cell() private function.

    QString Spreadsheet::formula(int row, int col) const
    {
    Cell *c = cell(row, col);
    if (c)
    return c->formula();
    else
    return "";
    } // End of Spreadsheet::formula() private function.

    void Spreadsheet::setFormula(int row, int col,
    const QString &formula)
    {
    Cell *c = cell(row, col);
    if (c) {
    c->setFormula(formula);
    updateCell(row, col);
    } else {
    setItem(row, col, new Cell(this, formula));
    }
    } // End of Spreadsheet::setFormula() private function.

    QString Spreadsheet::currentLocation() const
    {
    return QChar('A' + currentColumn())
    + QString::number(currentRow() + 1);
    } // End of Spreadsheet::currentLocation() function.

    QString Spreadsheet::currentFormula() const
    {
    return formula(currentRow(), currentColumn());
    } // End of Spreadsheet::currentFormula() function.

    QWidget *Spreadsheet::createEditor(int row, int col,
    bool initFromCell) const
    {
    QLineEdit *lineEdit = new QLineEdit(viewport());
    lineEdit->setFrame(false);
    if (initFromCell)
    lineEdit->setText(formula(row, col));
    return lineEdit;
    } // End of Spreadsheet::createEditor() function.

    void Spreadsheet::endEdit(int row, int col, bool accepted,
    bool wasReplacing)
    {
    QLineEdit *lineEdit = (QLineEdit *)cellWidget(row, col);
    if (!lineEdit)
    return;
    QString oldFormula = formula(row, col);
    QString newFormula = lineEdit->text();

    QTable::endEdit(row, col, false, wasReplacing);

    if (accepted && newFormula != oldFormula) {
    setFormula(row, col, newFormula);
    somethingChanged();
    }
    } // End of Spreadsheet::endEdit() function.

    void Spreadsheet::somethingChanged()
    {
    if (autoRecalc)
    recalculate();
    emit modified();
    } // End of Spreadsheet::somethingChanged() private function.

    bool Spreadsheet::writeFile(const QString &fileName)
    {
    QFile file(fileName);
    if (!file.open(IO_WriteOnly)) {
    QMessageBox::warning(this, tr("Spreadsheet"),
    tr("Cannot write file %1:\n%2.")
    .arg(file.name())
    .arg(file.errorString()));
    return false;
    }

    QDataStream out(&file);
    out.setVersion(5);

    out << (Q_UINT32)MagicNumber;

    QApplication::setOverrideCursor(waitCursor);
    for (int row = 0; row < NumRows; ++row) {
    for (int col = 0; col < NumCols; ++col) {
    QString str = formula(row, col);
    if (!str.isEmpty())
    out << (Q_UINT16)row << (Q_UINT16)col << str;
    }
    }
    QApplication::restoreOverrideCursor();
    return true;
    } // End of Spreadsheet::writeFile() function.

    bool Spreadsheet::readFile(const QString &fileName)
    {
    QFile file(fileName);
    if (!file.open(IO_ReadOnly)) {
    QMessageBox::warning(this, tr("Spreadsheet"),
    tr("Cannot read file %1:\n%2.")
    .arg(file.name())
    .arg(file.errorString()));
    return false;
    }

    QDataStream in(&file);
    in.setVersion(5);

    Q_UINT32 magic;
    in >> magic;
    if (magic != MagicNumber) {
    QMessageBox::warning(this, tr("Spreadsheet"),
    tr("The file is not a "
    "Spreadsheet file."));
    return false;
    }

    clear();

    Q_UINT16 row;
    Q_UINT16 col;
    QString str;

    QApplication::setOverrideCursor(waitCursor);
    while (!in.atEnd()) {
    in >> row >> col >> str;
    setFormula(row, col, str);
    }
    QApplication::restoreOverrideCursor();
    return true;
    } // End of Spreadsheet::readFile() function.

    void Spreadsheet::cut()
    {
    copy();
    del();
    } // End of Spreadsheet::cut() function.

    void Spreadsheet::copy()
    {
    QTableSelection sel = selection();
    QString str;

    for (int i = 0; i < sel.numRows(); ++i) {
    if (i > 0)
    str += "\n";
    for (int j = 0; j < sel.numCols(); ++j) {
    if (j > 0)
    str += "\t";
    str += formula(sel.topRow() + i, sel.leftCol() + j);
    }
    }

    QApplication::clipboard()->setText(str);
    } // End of Spreadsheet::copy() function.

    QTableSelection Spreadsheet::selection()
    {
    if (QTable::selection(0).isEmpty())
    return QTableSelection(currentRow(), currentColumn(),
    currentRow(), currentColumn());
    return QTable::selection(0);
    } // End of Spreadsheet::selection() private function.

    void Spreadsheet::paste()
    {
    QTableSelection sel = selection();
    QString str = QApplication::clipboard()->text();
    QStringList rows = QStringList::split("\n", str, true);
    int numRows = rows.size();
    int numCols = rows.first().contains("\t") + 1;

    if (sel.numRows() * sel.numCols() != 1
    && (sel.numRows() != numRows
    || sel.numCols() != numCols)) {
    QMessageBox::information(this, tr("Spreadsheet"),
    tr("The information cannot be pasted because the "
    "copy and paste areas aren't the same size."));
    return;
    }

    for (int i = 0; i < numRows; ++i) {
    QStringList cols = QStringList::split("\t", rows, true);
    for (int j = 0; j < numCols; ++j) {
    int row = sel.topRow() + i;
    int col = sel.leftCol() + j;
    if (row < NumRows && col < NumCols)
    setFormula(row, col, cols[j]);
    }
    }
    somethingChanged();
    } // End of Spreadsheet::paste() function.

    void Spreadsheet::del()
    {
    QTableSelection sel = selection();
    for (int i = 0; i < sel.numRows(); ++i) {
    for (int j = 0; j < sel.numCols(); ++j)
    delete cell(sel.topRow() + i, sel.leftCol() + j);
    }
    clearSelection();
    } // End of Spreadsheet::del() function.

    void Spreadsheet::selectRow()
    {
    clearSelection();
    QTable::selectRow(currentRow());
    } // End of Spreadsheet::selectRow() function.

    void Spreadsheet::selectColumn()
    {
    clearSelection();
    QTable::selectColumn(currentColumn());
    } // End of Spreadsheet::selectColumn() function.

    void Spreadsheet::selectAll()
    {
    clearSelection();
    selectCells(0, 0, NumRows - 1, NumCols - 1);
    } // End of Spreadsheet::selectAll() function.

    void Spreadsheet::findNext(const QString &str, bool caseSensitive)
    {
    int row = currentRow();
    int col = currentColumn(); + 1;

    while (row < NumRows) {
    while (col < NumCols) {
    if (text(row, col).contains(str, caseSensitive)) {
    clearSelection();
    setCurrentCell(row, col);
    setActiveWindow();
    return;
    }
    ++col;
    }
    col = 0;
    ++row;
    }
    gApp->beep();
    } // End of Spreadsheet::findNext() slot.

    void Spreadsheet::findPrev(const QString &str, bool caseSensitive)
    {
    int row = currentRow();
    int col = currentColumn() - 1;

    while (row >=0) {
    while (col >= 0) {
    if (text(row, col).contains(str, caseSensitive)) {
    clearSelection();
    setCurrentCell(row, col);
    setActiveWindow();
    return;
    }
    --col;
    }
    col = NumCols -1;
    --row;
    }
    gApp->beep();
    } // End of Spreadsheet::findPrev() slot.

    void Spreadsheet::recalculate()
    {
    int row;

    for (row = 0; row < NumRows; ++row) {
    for (int col = 0; col < NumCols; ++col) {
    if (cell(row, col))
    cell(row, col)->setDirty();
    }
    }
    for (row = 0; row < NumRows; ++row) {
    for (int col = 0; col < NumCols; ++col) {
    if (cell(row, col))
    updateCell(row, col);
    }
    }
    } // End of Spreadsheet::recalculate() slot.

    void Spreadsheet::setAutoRecalculate(bool on)
    {
    autoRecalc = on;
    if (autoRecalc)
    recalculate();
    } // End of Spreadsheet::setAutoRecalculate() slot.

    void Spreadsheet::sort(const SpreadsheetCompare &compare)
    {
    vector<QStringList> rows;
    QTableSelection sel = selection();
    int i;

    for (i = 0; i < sel.numRows(); ++i) {
    QStringList row;
    for (int j = 0; j < sel.numCols(); ++j)
    row.push_back(formula(sel.topRow() + i,
    sel.leftCol() + j));
    rows.push_back(row);
    }

    stable_sort(rows.begin(), rows.end(), compare);

    for (i = 0; i < sel.numRows(); ++i) {
    for (int j = 0; j < sel.numCols(); ++j)
    setFormula(sel.topRow() + i, sel.leftCol() + j,
    rows[j]);
    }

    clearSelection();
    somethingChanged();
    } // End of Spreadsheet::sort() slot.

    bool SpreadsheetCompare::eek:perator()(const QStringList &row1,
    const QStringList &row2) const
    {
    for (int i = 0; i < NumKeys; ++i) {
    int column = keys;
    if (column != -1) {
    if (row1[column] != row2[column]) {
    if (ascending)
    return row1[column] < row2[column];
    else
    return row1[column] > row2[column];
    }
    }
    }
    return false;
    } // End of SpreadsheetCompare::eek:perator() override function.
    ------------------------------------------------
    End of file: spreadsheet.cpp
    ------------------------------------------------

    Thanks again for any hints that you may be able to give me.

    Cheers,

    Sean Carrick
    PekinSOFT Systems
    PekinSOFT at gmail dot com
     
    , Mar 1, 2008
    #3
  4. Jerry Coffin Guest

    In article <02bba494-2c99-460a-994b-47c5ea9517d0
    @x41g2000hsb.googlegroups.com>, says...
    > Hey all,
    >
    > I'm working through the book "GUI Programming with Qt3" and have
    > worked my way through Chapter 4, creating a small spreadsheet
    > application. I'm finally to a point where I can compile the program
    > and see how it looks, but I keep get some cryptic error that I don't
    > understand. Maybe you all can help me out here.
    >
    > I've created many files and have all of them included properly in my
    > implementation files, so I know the problem is not there. The error
    > that I'm getting is as follows:
    >
    > -----------------------------------------------------------------------------------------------------------------------------------
    > spreadsheet.h: In member function 'bool Spreadsheet::autoRecalculate()
    > const':
    > spreadsheet.h:19: error: argument of type 'bool (Spreadsheet::)()'
    > does not match 'bool'
    > make: *** [mainwindow.o] Error 1
    >
    > -----------------------------------------------------------------------------------------------------------------------------------
    > The file in question, spreadsheet.h, has the following on line 19:
    >
    > bool autoRecalculate() const { return autoRecalc; }
    >
    > Now, I don't understand what the compiler is trying to tell me with
    > the statement, "argument of type bool (SPreadsheet::)() does not
    > match bool". Any help with this is greatly appreciated. Thank you
    > all for your time.


    The problem isn't with that function -- it's with the code that's
    (trying to, but not really) calling that function. Based on the error
    message, I'd guess you left the parentheses off of the code that was
    supposed to call the function. I.e. you probably have something like:

    bool x = some_spreadsheet.autoRecalculate;

    where you intended to have:

    bool x = some_spreadsheet.autoRecalculate();

    The error message is telling you that some_spreadsheet.autoRecalculate
    (without the parentheses) has the type:

    bool (SpreadSheet::)()

    which can't be assigned to a variable of type bool.

    // Feel free to skip the following. You can fix the problem without it.
    //
    It sounds like the compiler may have a little bit of a defect. You can
    get the address of a global function with the address-of operator, or by
    just giving the name of the function without parentheses. For example,
    this:

    int f() {}

    int (*pf)() = &f;

    and this:

    int f() {}

    int (*pf)() = f;

    are equivalent to each other.

    For member functions, however, that's not the case -- for a member
    function, you MUST use the address-of operator to get a pointer to a
    member function. I doubt you'd write the code to (properly) produce a
    pointer to a member by accident. If your code is as I've guessed above,
    it shouldn't really produce a pointer to a member function at all -- it
    should just be a syntax error. You need either the parentheses to call
    the function or else the address-of operator to take its address for the
    code to be valid at all.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
     
    Jerry Coffin, Mar 1, 2008
    #4
  5. Guest

    On Mar 1, 10:58 am, wrote:
    >
    > bool autoRecalc();
    >


    Jason,

    Thank you again for your help, but I do believe that I just found my
    mistake. Notice my declaration of the autoRecalc variable. I'm a
    moron and put parens after it for some reason. I've deleted the
    parens and am rerunning `make` as I type...

    OK, that error is gone! However, I've now got a bunch more that I
    need to look at. Thanks again for your help. I hope you have a great
    day.

    Cheers,

    Sean Carrick
    PekinSOFT Systems
    PekinSOFT at gmail dot com
     
    , Mar 1, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy K

    Confusing error message

    Andy K, Nov 18, 2003, in forum: Java
    Replies:
    3
    Views:
    530
    Sudsy
    Nov 18, 2003
  2. Alf P. Steinbach

    Confusing error ?!?!

    Alf P. Steinbach, Feb 28, 2004, in forum: C++
    Replies:
    2
    Views:
    340
    Poiquiop
    Feb 28, 2004
  3. Pmb
    Replies:
    65
    Views:
    2,974
    Old Wolf
    Jun 8, 2004
  4. SlowLearner
    Replies:
    16
    Views:
    706
  5. Wilson

    Confusing Error Message

    Wilson, Mar 23, 2007, in forum: C++
    Replies:
    12
    Views:
    691
    Old Wolf
    Mar 28, 2007
Loading...

Share This Page