I am trying to create a Screen class for SFML, however for some reason, the application works when using the Xcode example but as soon as I put the window into it's own class, it does not work. Why is this and how would I fix it?
Here is my code (adapted form the example):
Edit:
After reading the comments, I have changed to the following code. This still does not show a screen and the program still quits.
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include "ResourcePath.hpp"
class Screen{
public:
  sf::RenderWindow window;
  Screen(){
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
  }
};
int main(int, char const**)
{
  Screen* screen = new Screen();
  // Set the Icon
  sf::Image icon;
  if (!icon.loadFromFile(resourcePath() + "icon.png")) {
    return EXIT_FAILURE;
  }
  screen->window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
  // Load a sprite to display
  sf::Texture texture;
  if (!texture.loadFromFile(resourcePath() + "cute_image.jpg")) {
    return EXIT_FAILURE;
  }
  sf::Sprite sprite(texture);
  // Create a graphical text to display
  sf::Font font;
  if (!font.loadFromFile(resourcePath() + "sansation.ttf")) {
    return EXIT_FAILURE;
  }
  sf::Text text("Hello SFML", font, 50);
  text.setFillColor(sf::Color::Black);
  // Load a music to play
  sf::Music music;
  if (!music.openFromFile(resourcePath() + "nice_music.ogg")) {
    return EXIT_FAILURE;
  }
  // Play the music
  music.play();
  // Start the game loop
  while (screen->window.isOpen())
  {
    // Process events
    sf::Event event;
    while (screen->window.pollEvent(event))
    {
      // Close window: exit
      if (event.type == sf::Event::Closed) {
        screen->window.close();
      }
      // Escape pressed: exit
      if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
        screen->window.close();
      }
    }
    // Clear screen
    screen->window.clear();
    // Draw the sprite
    screen->window.draw(sprite);
    // Draw the string
    screen->window.draw(text);
    // Update the window
    screen->window.display();
  }
  return EXIT_SUCCESS;
}
 
     
    