SFML community forums

Help => General => Topic started by: Assassinbeast on October 31, 2012, 12:17:48 am

Title: Question about preprocessor
Post by: Assassinbeast on October 31, 2012, 12:17:48 am
Hey folks :)
i just want to show a small example about scope when dealing with preprocessor and functions that i have a little problem with

So.... i have the main functions and another function in a header... heres my code.

//MAIN.CPP

#include <SFML\Graphics.hpp>
#include "world1.h"

sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"dsadsa");
sf::Event ev;

int main()
{
        while(mywindow.isOpen())
        {
                while(mywindow.pollEvent(ev))
                {
                        if(ev.type == sf::Event::Closed)
                                mywindow.close();
                }
                world1();
               
        }
}
 

//WORLD1.H

#include <SFML\Graphics.hpp>

void world1()
{
        mywindow.clear(sf::Color(0,200,0));
        mywindow.display();
}
 

So basically, the problem is that an error aqquires and says that mywindow is unidentified.

I actually tried to define my RenderWindow variable "before" i #included the world1.h.
And that worked.... but is that really how you should do it to make my renderwindow variable be accessed in all function in other headers?
Title: Re: BASIC NEWB QUESTION about preprocessor
Post by: FRex on October 31, 2012, 12:21:42 am
Don't use \ unless you want to make special characters. Use / in paths, it'll work, always. \ might not.
Also, this is completely not how you should write code.
Title: Re: BASIC NEWB QUESTION about preprocessor
Post by: eXpl0it3r on October 31, 2012, 12:46:59 am
Also, this is completely not how you should write code.
Yes! :-\
This is not really related to SFML itself but rather a question on the basics of C++ programming. We surely help out on problems with C++ when using SFML, but for basics we can't really answer every little detail with enough depth that users would understand. For that problem there exist hundreds of C++ programming books and thousands of tutorials, which can teach you way better how to use C++. ;)
So please consult a C++ book and look up the chapter on preprocessor and as a hint from me, take a very long and deep look at the class section. :)
Title: Re: BASIC NEWB QUESTION about preprocessor
Post by: Assassinbeast on October 31, 2012, 01:09:59 am
argh!! okay  :(