c++ - 实例声明后 ';' 之前缺少 '*'

标签 c++ qt

我遇到了一个错误,我似乎无法在其他任何地方找到解决方案。

当我尝试声明“EncodeWindow”类的实例时发生错误。编译器给出错误 C2143、C4430 和 C2238。我只是想给“MainWindow”类一个“EncodeWindow”的实例。

文件mainWindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QString>
#include <QLabel>
#include "Image.h"
#include "encodewindow.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    /*Check whether a given file path is valid*/
    bool CheckFilePath(QString);

    /*Sets UI widgets*/
    void setOriginalImage_Label(const char*);
    void setEncodedImage_Label(const char*);
    void setDebug_TextBox(QString);        

    /*Saves all information about current encoding/decoding*/
    void saveFile();

private slots:    
    void on_Encode_Button_clicked();    
    void on_Reset_Button_clicked();
    void on_Save_Button_clicked();    
    void on_AddEncodeImage_Debug_Button_clicked();
    void on_AddImage_Button_clicked();
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
    EncodeWindow *CurrentEncodeWindow = new EncodeWindow;   //ERROR HERE!! C2143
    int fileNumber = 0;
};

#endif // MAINWINDOW_H

文件encodeWindow.h:

#ifndef ENCODEWINDOW_H
#define ENCODEWINDOW_H

#include <QMainWindow>
#include "mainwindow.h"

namespace Ui {
class EncodeWindow;
}

class EncodeWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit EncodeWindow(QWidget *parent = 0);
    ~EncodeWindow();

    /*Get filepaths from 'result' object (For access to filepaths without 'encode' Window)*/
    const char* getOriginalFilePath();
    const char* getEncodeFilePath();
    const char* getSaveFilePath();

    bool checkUI(const char*,const char*,const char*,bool*);
    bool CheckFilePath(const char*);
    std::string readInText(const char*);

private slots:
    void on_RedChannel_CheckBox_clicked(bool);
    void on_GreenChannel_CheckBox_clicked(bool);
    void on_BlueChannel_CheckBox_clicked(bool);
    void on_AlphaChannel_CheckBox_clicked(bool);
    void on_BitDepth_Slider_sliderMoved(int);
    void on_BitDepth_SpinBox_valueChanged(int);
    void on_Encode_Button_clicked();

private:
    Ui::EncodeWindow *ui;
    Encoded result;         //Enocoded object (child of Image class)
};

#endif // ENCODEWINDOW_H

任何帮助都会很棒。该代码是在 Qt 中为图像隐写术项目完成的。

谢谢。

最佳答案

您有循环包含。 “mainwindow.h”包括“encodewindow.h”,“encodewindow.h”包括“mainwindow.h”。包含守卫会停止循环,但是第一个包含的 header 的类定义将不会在第二个包含文件中完成,这将导致您的错误。

在上面的代码片段中,我在 encodewindow.h 中看到没有使用 mainwindow.h 中的任何内容,因此只需从 encodewindow 中删除 mainwindow.h 的包含.h.

关于c++ - 实例声明后 ';' 之前缺少 '*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43379935/

相关文章:

c++ - 如何检查使用 Aws::Transfer::Transfermanager 下载是否成功?

qt - 如何在 QWebView 中启用弹出窗口? [Qt]

c++ - QPushButton 打开 QWidget

qt - 如何抑制 Qt 主菜单键盘快捷键?

c++ - 如何将 HSV 转换为 RGB?

qt - 避免 QML 中的名称冲突

c++ - 带有 comptime 断言的整数常量表达式宏

c++ - 着色器语法 vector = vec3(a,b,c) 在 C++ 中?

c++ - 在结构中创建智能指针?

c++ - 在 C++ 中将数组作为参数传递