简体   繁体   中英

Why does MSVC produce C3668 error when overriding function with correct signature?

I am getting an error when trying to compile code that derives from QAbstractItemModel and overrides the data function despite matching the signature exactly.

The following code fails for me:

#include <QAbstractItemModel>

class A : public QAbstractItemModel 
{
        Q_OBJECT

public:
    A();

    virtual QVariant data(const QModelIndex &index, int role) const override; 
};

with the following error:

C3668: 'A::data': method with override specifier 'override' did not override any base class methods

This is only an issue when using MS Visual C++ 14.0 while the MinGW compiler I have works.

EDIT:

//  A.cpp

QVariant A::data(const QModelIndex &index, int role) const
{
    Q_UNUSED(index);
    Q_UNUSED(role);

    return QVariant();
}

The method signature you provide is correct. As Qt installations are different for both VC and MinGW, the problem may be due to an unwanted modification of QAbstractItemModel.h in the VC version (for example, you were debugging and unconsciously edited the header file).

Check the header hasn't been modified and if so, restore it from a backup or another installation (same version).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM