SFML community forums

Help => General => Topic started by: infernotnt on August 30, 2016, 02:45:07 pm

Title: Function problems in c++ and SFML
Post by: infernotnt on August 30, 2016, 02:45:07 pm
.........
void foo(RenderWindow window){

 window.draw(bar);

}
........
int main(){

 RenderWindow window(....);//i have to define it in int main!

 foo(window);


return 0;
}


I need the function to work but the problem is that i need to define the window in int main but then i can't use the function, I tried using pointers but I suck with pointers so that was no good, offer a solution please.
Title: AW: Function problems in c++ and SFML
Post by: eXpl0it3r on August 30, 2016, 03:01:48 pm
You can't define or declare a function within another function.
Use a reference instead of trying to pass a copy.

Additionally I advice you to first learn a bit more about C++ itself before jumping into using other libraries.
Title: Re: Function problems in c++ and SFML
Post by: infernotnt on August 30, 2016, 05:09:26 pm
Okay, just tell me how do I do it, I will be very happy, I have a few years of problem solving expirience in c++ so I suck with pointers as I never needed them for problem solving competitions(logic and math), thank you!
I am very good from learning from seeing a example!
Title: AW: Function problems in c++ and SFML
Post by: eXpl0it3r on August 30, 2016, 07:26:46 pm
If you can't figure out what to do when I tell you to use a reference, then it's time to look up that term.
Title: Re: Function problems in c++ and SFML
Post by: infernotnt on August 30, 2016, 10:36:10 pm
Ah my bad I look realy dumb here, I suceeded but I didn't realise I was compiling the wrong thing the whole time sorry!