试图声明静态成员函数 - “不是Class的成员”错误

时间:2014-06-02 14:46:03

标签: c++ c++11

这是我的代码:

//portmanager.cpp
#include "portmanager.h"

void PortManager::setupQuestions() {
    QMap<QString, QVector<quint8>> commandMap;
    QVector<quint8> v;
    v = {0xF0, 0xC0, 0x4F}; commandMap.insert("check digit", v);
    //some code
    QVector<Question*> *questions = this->questions;
    for (QString commandKey : commandMap.keys()) {
        Question *question = new Question;
        question->name = commandKey;
        question->data = &commandMap[commandKey];
        question->byteData = Engine::dataToByteBata(question->data);
        questions->push_back(question);
    }
}

PortManager::PortManager(QObject *parent) :
    QObject(parent)
{
    this->engine = (Engine*) parent;
    this->setupQuestions();
}

它给我这样的错误:

  

portmanager.cpp:19:错误:'dataToByteBata'不是'Engine'的成员

     

question-&gt; byteData = Engine :: dataToByteBata(question-&gt; data);

但我很确定它是会员:

//engine.h
#include "mainwindow.h"

class DatabaseManager;
class PortManager;

class Engine : public QObject
{
    Q_OBJECT
public:
    static QByteArray dataToByteData(QVector<quint8> const& data) {
        QByteArray* byteData = new QByteArray;
        for (quint8 h : data) {
            byteData->append(h);
        }
        return *byteData;
    }

    explicit Engine(QObject *parent = 0);

signals:

public slots:

private:
    MainWindow *mainWindow;
    DatabaseManager *databaseManager;
    PortManager *portManager;
    QTimer *timer;
};

在调用函数的那一刻,Engine还没有完全构造但已经完全声明:

//engine.cpp
#include "engine.h"
#include "databasemanager.h"
#include "portmanager.h"

Engine::Engine(QObject *parent) :
    QObject(parent)
{
    this->mainWindow = (MainWindow*) parent;
    this->databaseManager = new DatabaseManager(this);
    this->portManager = new PortManager(this);
}

但它是静态函数所以它应该就像我会使用命名空间而不是类,对吧?我的代码出了什么问题?

1 个答案:

答案 0 :(得分:4)

dataToByteBatadataToByteData不同。 /线程

相关问题