std vector push_back':2个重载没有'this'指针错误的合法转换

Sam*_*mer 1 c++ qt stl vector

我有这个qt应用程序,在我的头文件中

class report_intro: public QWizardPage
{
    Q_OBJECT

public:
    report_intro(QWidget *parent = 0);
    ~report_intro(void);
    int nextId() const;
private:
    Ui::Rep_Wiz_Intro ui; 
    QWidget *pWnd;
    std::vector<int> m_vTests;
    int m_iNumTest; 
};
Run Code Online (Sandbox Code Playgroud)

在我有的Cpp文件中

int report_intro::nextId() const
{   
    int i;
    // check to see which check box was checked 
    for (i=1; i<m_iNumTest; i++)
    {
        QString str = QString("checkBox_T%1").arg(i);
        if ((ui.groupBox_tests->findChild<QCheckBox *>(str))->isChecked())
            m_vTests.push_back(i); // **** here is the error****
    }
        return newreport::report_page; 
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

error C2663: 'std::vector<_Ty>::push_back' : 2 overloads have no legal conversion for 'this' pointer
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助...

Nat*_*ica 7

int report_intro::nextId() const被标记为const.该说明者承诺你不会改变班级的州/成员.

m_vTests.push_back(i);当你改变时违反了这一点m_vTests.

您需要const从函数中删除说明符或声明m_vTestsmutable可以在const函数中修改它.