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

Author Topic: Function problems in c++ and SFML  (Read 1271 times)

0 Members and 1 Guest are viewing this topic.

infernotnt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Function problems in c++ and SFML
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Function problems in c++ and SFML
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

infernotnt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Function problems in c++ and SFML
« Reply #2 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!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Function problems in c++ and SFML
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

infernotnt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Function problems in c++ and SFML
« Reply #4 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!

 

anything