c++ - 标准 vector push_back' : 2 overloads have no legal conversion for 'this' pointer error

标签 c++ qt vector stl

我有这个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; 
};

在我的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; 
}

我收到这个错误:

error C2663: 'std::vector<_Ty>::push_back' : 2 overloads have no legal conversion for 'this' pointer

感谢您的帮助...

最佳答案

int report_intro::nextId() const 被标记为 const。该说明符 promise 您不会更改类的状态/成员。

m_vTests.push_back(i); 在您更改 m_vTests 时违反了这一点。

您需要从函数中删除 const 说明符或将 m_vTests 声明为 mutable 以便它可以在 const 中修改 函数。

关于c++ - 标准 vector push_back' : 2 overloads have no legal conversion for 'this' pointer error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36651084/

相关文章:

c++ - 如何在 OS X 上使用 QSettings 存储 INI 文件

c++ - 使用 QMathGL 绘制实时数据?

c++ - 从未知长度的手动输入中提取单个单词

c++ - 如何在 C++ 中将 float 组添加到浮点 vector

c++ - 使用虚拟键停止定时器

c++ - 如何同时运行两个线程? Qt C++

c++ - 用 C++ lambda 模仿 Obj-C block 行为

c++ - 为什么不支持 QCamera::CaptureVideo?

c++ - 如何将输入值拆分为 4 位 vector ,例如将 n 位拆分为每个部分 vector 的半字节?

c++ - 打开文件流输入的 Getline 问题