So I am new to C++ and I am trying to use an inner class like this:
struct PreviousButton {
SelectionScreen* ss;
PreviousButton(SelectionScreen* sss) {
ss = sss;
}
void ClickAction() {
//images is a vector with images. in here it is empty
ss->images;
}
};
This inner class is inside the class SelectionScreen and I need to perform a click action and need some of the variables of the selectionscreen.
SelectionScreen:
class SelectionScreen {
public:
void AddImage(Image img);
std::vector<Image> images;
How I fill the vector:
Image* image = new Image{ };
AddImage(*image2);
AddImage method:
void SelectionScreen::AddImage(Image img)
{
images.push_back(img);
}
But when I try to use the selectionscreen inside the class all of the variables are empty. But when I look into selectionscreen all of the variables are set.
The way I pass the SelectionScreen:
PreviousButton* previousButton = new PreviousButton(*ren, this);
How SelectionScreen gets initialized: (this method is called from the main)
int Program::Render() {
bool quit = false;
MenuScreen m = SelectionScreen{ Sdl_Renderer };
// change current screen to selectionscreen
ScreenController::GetInstance().ChangeMenu(m);
while (!quit) {
// handle user input and repaint
}
// delete all windows if quit is true
SDL_DestroyRenderer(Sdl_Renderer);
SDL_DestroyWindow(Sdl_Window);
SDL_Quit();
return 0;
}
Does anyone knows why my variables are empty?