this post was submitted on 04 Apr 2026
5 points (100.0% liked)

C++

2259 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 2 years ago
MODERATORS
 

So i am basically almost done with my C++ App Logic Wise tho the only thing i struggle with and wanna figure it is how to include a seperate class into my main class constructors >.>

Mostly due to the fact that currently in my Code my main Code has 2 Objects tho ErrorWin Object is right now the only one that exist twice as seperate Objects which itd like to fix >.>

So this is my first Object in my Main Function which just calls my DisplayWindow Function while my ErrorWin Object calls the Display Error Window Function :P

int main() {
  ErrorWindow ErrorWin;
  MainWindow MainWin;

  if (ProgramPath.empty()) {
    ErrorWin.DisplayErrorWindow();
    return Fl::run();
  }

  MainWin.DisplayMainWindow();
  return Fl::run();
}

Now the Main Issue is that only my First Text basically gets displayed in the Error Window even tho my switch Statement is set to display a different error text basically according to my callback but that obviously does not work due to theyre being seperate ErrorWin Objects :(

void MainWindow::CallbackSaveFile(Fl_Widget* Widget, void* Data) {
  MainWindow* MainWindowData = static_cast<MainWindow*>(Data);
  ErrorWindow ErrorWin;

  if (!MainWindowData->InputFile.empty()) {
    ...
  } else {
    ErrorWin.DisplayErrorWindow();
  }
}
you are viewing a single comment's thread
view the rest of the comments
[–] p_consti@lemmy.world 2 points 2 days ago* (last edited 2 days ago) (1 children)

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.

[–] RetroHax@feddit.org 1 points 2 days ago* (last edited 2 days ago) (1 children)

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

[–] p_consti@lemmy.world 2 points 2 days ago

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.