>>Can you please tell me what is meant by forward declaration?
A forward-declaration is just a way to tell the compiler that there will eventually be a class declared later in the code. It is only a means to stop the compiler from complaining that it doesn't recognize the type or class. Of course, this is only temporary, the actual declaration of the class has to appear eventually (if it is ever used). When there is only a forward-declaration available so far (as the compiler is looking through the code), you only can do very limited uses of the class in question. Because the compiler doesn't know what that class is, only that it is a valid class, you cannot use any of its member functions or anything, you cannot create an object of that class, you cannot have data members of that class or inherit from it, all you can do is declare pointer / reference parameters or data members to an object of that class. Forward-declarations are typically used when you have two classes that depend on each other (and in other more advanced cases). Here is a simple and typical pattern that involves a forward-declaration:
class Cat; // forward-declaration.
class Dog {
public:
void ChaseThisCat(Cat& someCat); //use of forward-decl. to declare a reference parameter.
};
class Cat {
public:
void FleeFromThisDog(Dog& someDog);
};
// Now, Cat has been declared and can be used to implement the member function of Dog:
void Dog::ChaseThisCat(Cat& someCat) {
//... use Cat class as much as you like.
};
void Cat::FleeFromThisDog(Dog& someDog) {
//... ditto.
};
>>And what is the difference between including the header file of a class and the declaration of the itself?
Using headers, they are saved in your hard-drive as two files. That's about it. The #include statements are, for all intent and purposes, the same as a copy-paste operation. That is, #include "my_file.h" tells the compiler: "Go and find the file 'my_file.h' and replace this line with the content of that file." So, it just copies the entire content in-place of the include statement. At the end, you get one big source file that the compiler will look through from start to end. Of course, the process is not quite as simple as a copy-paste (there is some bookkeeping done and other things), but these are just things the compiler will do behind the scenes, the behavior is exactly as if you copy-pasted it.
This is why it is so important to have header-guards too, to make sure the same content of the header files don't get copied many times, causing repeating declarations / definitions, which breaks the One Definition Rule (ODR) of C/C++.
The advantages of header files as opposed to everything in one file (main.cpp) are pretty obvious I think. You can actually reuse the header files without having to constantly copy-paste manually. And so on..
There should never be a difference in behavior (by the compiler) between including a header file and copying its content manually. If you fixed your problem by not including the header file and instead declaring the class UmerWindow directly inside this askdialog file, then this is not what fixed the problem, something else is going on (something else was changed). I guarantee that. You should probably look at what is different between the code you added to askdialog.h and what code appears in umerwindow.h, that's how you're gonna understand how the problem disappeared and how to avoid similar problems in the future. Sometimes you change a few insignificant things and it fixes the problem, but it's not magic, there is a reason why the error was fixed and you should investigate to find out what that is, otherwise, this painful experience is bound to occur again (and the "magic" trick that fixed it this time is unlikely to work again).