Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Question about preprocessor  (Read 1755 times)

0 Members and 1 Guest are viewing this topic.

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Question about preprocessor
« 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?
« Last Edit: October 31, 2012, 08:04:46 am by Laurent »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: BASIC NEWB QUESTION about preprocessor
« Reply #1 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.
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: BASIC NEWB QUESTION about preprocessor
« Reply #2 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Re: BASIC NEWB QUESTION about preprocessor
« Reply #3 on: October 31, 2012, 01:09:59 am »
argh!! okay  :(

 

anything