I am creating a project that uses a dll resource named GUI.dll for its dialogs.
At first, when I had everything in the .cpp except a few lines (that were in the header), the GUI.cpp looked like
class AuswertungsGUI : public Dialog
{
public:
AuswertungsGUI() : Dialog(DA_Window, "GUI")
{
InitMsgMap();
}
that worked. But now I've split everything up into a header GUI.h with the class declaration and the GUI.cpp with the implementation. I obviously don't know how to create the appropriate dialog out off the resource:
GUI.h:
#ifndef AUSWERTUNGSGUI_H
#define AUSWERTUNGSGUI_H
#include <Origin.h>
class AuswertungsGUI:public Dialog
{
public:
AuswertungsGUI();
~AuswertungsGUI();
private:
//...
};
GUI.cpp:
#include "GUI.h" //Definition der Klassen: AuswertungsGUI, ...
AuswertungsGUI::AuswertungsGUI():Dialog(DA_Window, "GUI")
//Dialog( LPCTSTR DlgName, LPCTSTR DllName )
{
InitMsgMap();
}
AuswertungsGUI::~AuswertungsGUI() //Desktruktor
{
printf("Im Desktrutor\n");
this->Close();
}
Error at GUI.h in line class AuswertungsGUI:public Dialog. The compiler says (translated): Invalid keyword, expcted identifier of base class, then
class/struct not found and then error in declaration of datatype
In this case, the compiler is complaining that Dialog isn't a base class identifier because it hasn't encountered its declaration (and thus can't subclass it, as it doesn't "know" it).
Include the header that contains Dialog and it'll be fine.
Related
I'm using wxWidgets with CodeBlocks, and I'm trying to instantiate a class called FileManager as an attribute of the Frame for wxWidgets, and pass the wxFrame parent to the constructor of FileManager. The objective is to be able to able to refer to the wxFrame from within FileManager. I'm getting an error "FileManager does not name a type". Not sure what I'm doing wrong thanks
The project is called "MullSimple_CB" so the main frame class is "Mull_Simple_CBFrame" Here are the files.
So the main object is a wxFrame object of class MullSimple_CBFrame, defined inside MullSimple_CBMain. The class I want instantiated as a member of that class is FileManager
MullSimple_CBMain.h
#ifndef MULLSIMPLE_CBMAIN_H
#define MULLSIMPLE_CBMAIN_H
#include "non-wx/file_manager.h"
class MullSimple_CBFrame: public wxFrame
{
public:
MullSimple_CBFrame(wxWindow* parent,wxWindowID id = -1);
virtual ~MullSimple_CBFrame();
// ERROR ON THIS LINE:
// "'FileManager' does not name a type"
FileManager fileManager(MullSimple_CBFrame parentFrame);
private
DECLARE_EVENT_TABLE()
};
#endif // MULLSIMPLE_CBMAIN_H
MullSimple_CBMain.cpp
#include "wx_pch.h"
#include "MullSimple_CBMain.h"
#include <wx/msgdlg.h>
#include "non-wx/file_manager.h"
MullSimple_CBFrame::MullSimple_CBFrame(wxWindow* parent,wxWindowID id)
{
FileManager fileManager(this);
}
FileManager.h
#ifndef FILE_MANAGER_H_INCLUDED
#define FILE_MANAGER_H_INCLUDED
#include "../MullSimple_CBMain.h"
class FileManager
{
private:
MullSimple_CBFrame storeMainFrame;
public:
// constructor
FileManager(MullSimple_CBFrame mainFrame);
};
#endif // FILE_MANAGER_H_INCLUDED
FileManager.cpp
#include "file_manager.h"
#include "../MullSimple_CBMain.h"
FileManager::FileManager(MullSimple_CBFrame mainFrame): storeMainFrame(mainFrame))
{
}
Your file_manager.h file includes MullSimple_CBMain.h and the MullSimple_CBMain.h file includes your file_manager.h.
You end up with a never ending chain of includes... which never resolve.
Consider putting forward declarations into a single .h file and then have your .h files only include it as opposed to including the individual class.h files themselves. The only time you need to include the class.h files themselves is if you need the compiler to know about the full definition of the class as opposed to just knowing the class exists at all.
I am building a 3d painter in C++ with OpenGL and MFC.
I created dialogs for creating every shape that i have: like cube, cylinder and etc...
My cube class inherits the cylinder class with the difference of amount of stack and slices only.
Hence the CreateCylinder dialog should look the same as the CreateCube dialog.
I was able to inherit it fine, but i have an error that says:
Error 6 error C2065: 'IDD_BASEWIN_DIALOG' : undeclared identifier c:\users\l122\desktop\opengl\opengl\basewindlg.h 19 1 OpenGL
This happens every new compilation after some minor code changes.
To fix it, i comment this line:
enum { IDD = IDD_BASEWIN_DIALOG };
then compile and uncomment the same line, which helps in the next compilation to work fine.
That how i inherited the CreateCylinder dialog class in my CreateCube dialog class:
IMPLEMENT_DYNAMIC(CreateCube, CreateCylinder)
CreateCube::CreateCube()
: CreateCylinder(this->GetSafeOwner())
{
}
CreateCube::~CreateCube()
{
}
void CreateCube::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
CreateCylinder::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CreateCube, CreateCylinder)
END_MESSAGE_MAP()
and i also edited this line in the CreateCylinder constructor:
CreateCylinder::CreateCylinder(CWnd* pParent /*=NULL*/)
: CDialogEx(CreateCylinder::IDD, this->GetSafeOwner())
The header file:
#pragma once
#include "CreateCylinder.h"
// CreateCube dialog
class CreateCube : public CreateCylinder
{
DECLARE_DYNAMIC(CreateCube)
public:
CreateCube(); // standard constructor
virtual ~CreateCube();
// Dialog Data
enum { IDD = IDD_CREATE_CUBE_DLG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
I want to know what have i done wrong with the inheritance. is it necessary to send parent's pointer to the base dialog as i did?
And is the error above has to do anything with it?
The problem here is the scope of the enum symbol IDD_CREATE_CUBE_DLG. When you inherit a class, you don't inherit it's "symbol scope", you merely inherit its "members namespace". I'm sure some language lawyer can give a more precise (technically correct) explanation. But, a simple explanation is that you don't inherit symbol - thus enum - definitions. You should be able to access them even if they are in protected scope, though.
So, assuming that IDD_CREATE_CUBE_DLG is used in CreateCylinder class to set "its" IDD, then, instead of:
enum { IDD = IDD_CREATE_CUBE_DLG };
you should write:
enum { IDD = CreateCylinder::IDD };
I think that the correct wording would be to say that you need the "fully qualified" name here.
This is actually a good thing, and some class libraries use it to play tricks, like enumerating messages supported by a class, and such - see, for example, the FOX (widget) toolkit library.
UPDATE:
If you change your declaration as is updated here, thus avoiding the use of IDD_CREATE_CUBE_DLG, it's probable that you won't have problems with IDD_CREATE_CUBE_DLG any more. But, if you still do, the problem would be that IDD_CREATE_CUBE_DLG, since it's declared in Resource.h, then, at the time it was used (which is the line for which the error is reported), the Resource.h wasn't (properly) included. So, check what is the .cpp file that is compiled when your error is reported. Then check the includes in that file. You should clean them up, but, for starters, you may "just" #include "Resource.h" at the top (of the .h file).
As for the constructor of CDialogEx, just pass the parameter along, like this:
CreateCylinder::CreateCylinder(CWnd* pParent)
: CDialogEx(CreateCylinder::IDD, pParent)
Actually adding resource.h to my base dialog header solved the problem. I just can't understand how it worked flawlessly, before i have added the inherited classes. In both cases this header file wasn't included, so how did it work in a first place?
I have some misunderstanding:
A.h
#ifndef A_H
#define A_H
#include "B.h"
class A : public B
{
Q_OBJECT
public:
A();
};
#endif
A.cpp
#include "A.h"
A::A()
{
B::ui->blancH2->setValue(2);
}
B.h
#include <QWidget>
#ifndef B_H
#define B_H
namespace Ui {
class B;
}
class B
{
Q_OBJECT
public:
explicit B(QWidget *parent = 0);
public:
Ui::B *ui;
};
#endif
As result of compiling I have next errors:
A.cpp: In constructor 'A::A()': invalid use of incomplete type 'class Ui::B'
B.h: forward declaration of 'class Ui::B'
Can anybody explain why I have this errors?
Check you ui_B.h. At the end of it, you should see
namespace Ui {
class B: public Ui_B {};
}
If it's not, you can open you .ui file in Qt Designer, select your widget, and in Object Inspector, change the string under 'Object' to 'B'. The default value is 'Dialog' if your widget is a dialog.
Don't modify ui_B.h directly since it's generated by Qt compiler and it will be overwritten every time you compile.
As the error says, there is no definition of Ui::B available, only the declaration in B.h; and you can't write code that accesses members of a class unless the class has been defined.
You need to include whichever header defines Ui::B; or, perhaps, give B a member function to do whatever A needs doing, rather than furtling with B's members directly.
In Qt Creator, open the dialog form. Select the dialog panel and on the right be sure that the Object Name is B.
That will let the Qt build system know that your object is a UI object. Without this, your program only knows your panel as an object name Dialog.
Actually I met this problem when I've changed the name of 'MainWindow' to 'LoginWindow' after the whole app is established.This can't be useful for everyone but change the name of it to the original one(which you filled in when start the project) can work for me.
Still don't know about .ui files of Qt hoping anyone can explain this~
I have a dialog window settings that I want to display all values from my breadData object, and to do so I want to have settings inherit breadData's protected members. I try to forward declare breadData, but I'm getting a couple errors in my code.
/home/--/breadPull/prj/settings.h:14: error: invalid use of incomplete type 'struct breadData'
/home/--/breadPull/prj/resultwnd.h:7: error: forward declaration of 'struct breadData'
For one, breadData is not a struct, why does the compiler think breadData is a struct? Secondly I don't understand what the second line is trying to say. My only guess is because there are a lot of circular dependencies in my program. Here's the relevant code:
settings.h
#include <QDialog>
#include "breaddata.h"
class breadData;
namespace Ui {
class Settings;
}
class Settings : public QDialog, public breadData
{
Q_OBJECT
//.....
breadData.h
#include <vector>
#include <string>
#include <QtWidgets>
#include <QMainWindow>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "resultwnd.h"
#include "settings.h"
class MainWindow;
class resultWnd;
class breadData
{
public:
breadData(std::string);
~breadData();
//read in data file that provides all information
bool readData();
//.......
resultWnd.h
include <QGroupBox>
#include "breaddata.h"
class breadData;
namespace Ui {
class resultWnd;
}
class resultWnd : public QGroupBox
//.....
You have a circular dependency. breaddata.h includes settings.h before declaring breaddata. settings.h requires the declaration of breaddata for the inheritance.
Thus the file the preprocessor creates when compiling a file that includes breaddata first looks like this (indentation to visualize the recursive insertion of included header files):
<content of breaddata.h>:
<content of vector, string, QtWidget, QMainWindow, mainwindow.h and ui_mainwindow.h>
...
<content of resultWnd>:
...
class breaddata; //forward declaration mentioned in the error message
...
<content of settings.h>:
...
class Settings : public QDialog, public breadData //DANG!
...
class breaddata { ... //too late
Summarized:
class breaddata; //forward declaration mentioned in the error message
...
class Settings : public QDialog, public breadData //DANG!
...
class breaddata { ... //too late
The solution here is to avoid the includes in breaddata.h, especially settings.h. If necessary, forward-declare Settings. The rule of thumb is to include in headers only if you must, and forward-declare whenever you can.
Your problem is that you have an incomplete understanding of the following:
The precompiler
The difference between declarations and definitions and purpose of using the former.
The purpose and use of namespaces
Without knowing more about your code than what you've shown, the following should solve your problem:
settings.h
#ifndef SETTINGS_H
#define SETTINGS_H
// Your code as above
#endif
breaddata.h
#ifndef BREADDATA_H
#define BREADDATA_H
// Your code as above
#endif
resultWnd.h
#ifndef RESULTWND_H
#define RESULTWND_H
// Your code as above
#endif
I suspect that this will not solve your problem entirely though. Based on your second error message, I suspect you have left important lines of code out of your question so nobody will be able to give you a definitive answer to solve your problem.
I suggest you edit the code in your question to include all lines that contain the breadData, Settings and resultWnd
It is possible to solve this, we just need to see how the three classes are bound together so we can help you untangle them.
The reason the compiler thinks you're using a struct is purely historical. The class keyword was introduced in C++ with the intention to replace the struct. Previously, in C, only the struct keyword exists. As far as I know, the only difference between structs and classes is the default access level. classes default to private while structs default to public. Otherwise, they have identical usage.
I checked out a post similar to this but the linkage was different the issue was never resolved. The problem with mine is that for some reason the linker is expecting there to be a definition for the base class, but the base class is just a interface. Below is the error in it's entirety
c:\users\numerical25\desktop\intro todirectx\godfiles\gxrendermanager\gxrendermanager\gxrendermanager\gxdx.h(2) : error C2504: 'GXRenderer' : base class undefined
Below is the code that shows how the headers link with one another
GXRenderManager.h
#ifndef GXRM
#define GXRM
#include <windows.h>
#include "GXRenderer.h"
#include "GXDX.h"
#include "GXGL.h"
enum GXDEVICE {
DIRECTX,
OPENGL
};
class GXRenderManager {
public:
static int Ignite(GXDEVICE);
private:
static GXRenderer *renderDevice;
};
#endif
at the top of GxRenderManager, there is GXRenderer , windows, GXDX, GXGL headers. I am assuming by including them all in this document. they all link to one another as if they were all in the same document. correct me if I am wrong cause that's how a view headers. Moving on...
GXRenderer.h
class GXRenderer {
public:
virtual void Render() = 0;
virtual void StartUp() = 0;
};
GXGL.h
class GXGL: public GXRenderer {
public:
void Render();
void StartUp();
};
GXDX.h
class GXDX: public GXRenderer {
public:
void Render();
void StartUp();
};
GXGL.cpp and GXDX.cpp respectively
#include "GXGL.h"
void GXGL::Render()
{
}
void GXGL::StartUp()
{
}
//...Next document
#include "GXDX.h"
void GXDX::Render()
{
}
void GXDX::StartUp()
{
}
Not sure whats going on. I think its how I am linking the documents, I am not sure.
The problem is You need to have #include "GXRenderer.h" at the top of both: GXGL.h and also GXDX.h.
The base type must be defined not just declared before defining a derived type.
By the way, the error is a compiling error not linking error.
Edit: About your class type redefinition:
at the top of every header file you should have #pragma once.
The #pragma once directive specifies that the file will be included at most once by the compiler in a build.
You included them all into GXRenderManager.h, meaning that GXRenderManager.h is OK.
But you forgot to include them all into GXGL.cpp and GXDX.cpp. In these .cpp files GXRenderer class is completely unknown.
There are at least two "schools" of #include strategies. One says that header file must include everything that is needed for its own compilation. That would mean that GXGL.h and GXDX.h must include GXRenderer.h. If you followed that strategy, your GXGL.cpp and GXDX.cpp would be OK as they are now.
Another "school" says that header files must not include each other at all, i.e. all inclusions must be done through .cpp files. At first sight one could guess that your GXGL.h and GXDX.h follow that strategy (since you are not including anything into them), but then your GXRenderManager.h looks completely different.
You need to decide which strategy you are trying to follow and follow it. I'd recommend the first one.
I got an error C2504: 'CView' : base class undefined
where CView is not directly my base class from which I am inheriting.
I am inherting mYClass from MScrollView, "for this matter any class which is not actual Base Class is what the point is to be noted down here"
but the error is the C2504. When I have included it in the header where this problem is arising, this problem is resolved.
#include "stdafx.h"
where stdafx.h has #include which contains all the basic class defined...hope this answer resolves everyone who are facing this issue.