我遇到了一个错误,我似乎无法在其他任何地方找到解决方案。
当我尝试声明“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/