I'm trying to use SFML's RenderWindow class from another function, but I keep getting an error, and honestly, I have no clue why I am getting the error. I'm referencing the "myWindow" variable in the parameter list, and everything has been declared. I'm getting frustrated. I've Googled tons of tutorials and articles, and I can't pinpoint why this error is happening. Here's the code:
#include <SFML/Graphics.hpp>
#include "declarations.h"
int main()
{
//create the main window
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Title");
//start the game loop
while (window.isOpen())
{
//process events
sf::Event event;
while (window.pollEvent(event))
{
//close window: exit
if (event.type == sf::Event::Closed) window.close();
}
windowHandler(myWindow); //Right here is where I am getting the error
}
return EXIT_SUCCESS;
}
-----------------------------------
#ifndef DECLARATIONS_H_
#define DECLARATIONS_H_
const short SCREEN_WIDTH = 256;
const short SCREEN_HEIGHT = 240;
void windowHandler(sf::RenderWindow& myWindow);
#endif
-----------------------------------
#include <SFML/Graphics.hpp>
#include "declarations.h"
void windowHandler(sf::RenderWindow& myWindow)
{
//clear screen
myWindow.clear();
//draw to screen, will update this later, right now it doesn't draw anything
//window.draw();
//update the window
myWindow.display();
}
The error I get:
In function 'int main()':|
error: 'myWindow' was not declared in this scope|
I don't understand why I am getting this error. Everything is declared, and myWindow is referenced with an &. The function prototype is included in the declarations header file, and the header file is included before it even touches main(), which means it should be able to be used anywhere in the program. So why is it telling me that 'myWindow' is not declared in this scope. It is!
If you know the answer to the problem, it would greatly be appreciated. Thank you so much.