Initialize ErrorWin as a pointer. Instantiate it in main (or at initialization).
Remember to delete the data in the destructor.
The center for all discussion and news regarding C++.
Initialize ErrorWin as a pointer. Instantiate it in main (or at initialization).
Remember to delete the data in the destructor.
huh? O.o
so you mean like this for Example? >.>
int main() {
ErrorWindow* ErrorWin;
MainWindow MainWin(&ErrorWin);
and then inside mainwindow source files like this? O.o
class MainWindow {
public:
MainWindow(ErrorWindow* ErrorWin);
private:
ErrorWindow* ErrWin;
MainWindow::MainWindow(ErrorWindow* ErrorWin) : ErrWin(ErrorWin) {
because all i recieve is this error even tho i included errorwindow.hpp inside mainwindow.hpp and cpp file >.>
In file included from src/gui/errorwindow.hpp:20,
from src/main.cpp:13:
src/gui/mainwindow.hpp:56:27: error: expected ‘)’ before ‘*’ token
56 | MainWindow(ErrorWindow* ErrorWin);
| ~ ^
| )
src/gui/mainwindow.hpp:83:5: error: ‘ErrorWindow’ does not name a type
83 | ErrorWindow* ErrWin;
| ^~~~~~~~~~~
make: *** [Linux.mk:39: build/main.o] Error 1
First, in your main, you want judt ErrorWindow ErrorWin;. As it is, you're taking a pointer to a pointer with the & (also it's not initialized).
Second, does your MainWindow.hpp know the ErrorWindow? You may have to forward declare it (write class ErrorWindow; at the top, to tell the compiler it exists without saying anything else). If you include the other header files respectively, they include each other, so you get a cycle.
yup just removed the infinite cycle by just doing class ErrorWindow; inside mainwindow.hpp :P
also if i remove MainWindow MainWin; from main then obviously all i get is a compiler Error as i require MainWin inside my Main Function >.>
src/main.cpp:20:5: error: ‘MainWin’ was not declared in this scope; did you mean ‘MainWindow’?
I did not mean to remove MainWindow from main, I meant you shoud change ErrorWindow* ErrorWin to ErrorWindow ErrorWin, because you don't want a pointer variable, you want an instance, and then you pass a pointer to the instance using &ErrorWin as you did.
Can you elaborate what exactly you wish to achieve? You could pass a pointer to the instance of one class in the constructor of the other.
Also, I would recommend to make you variables start with lower-case, to distinguish from class names. Makes it easier at a glance.
Basically my Idea is/was to use 1 Function that being DisplayErrorWindow and have all the Errortexts basically inside it as nothing ever changes aside from the Text i couldve just used if statements :P
But sadly it wiull only display the first Error Text and not any of the other Error Texts no matter what i modify and i did already check my if statement Logic inside the Function and nothings wrong on that Part :c
Without more code it's impossible to say what your problem is. Are you expecting a function to be called that isn't? Use a debugger to go through if so.