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

Author Topic: Lost in the basics of Function?  (Read 1244 times)

0 Members and 1 Guest are viewing this topic.

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Lost in the basics of Function?
« on: May 13, 2014, 06:11:20 am »
I know this is very basic, but for some reason i can't seem to remember nor grasp on its approach.
I've read that, the window: "sf::RenderWindow renderWindow;" must be in the same function as the events.

However, how can i create a separate function using specific sf::RectangleShape Objects that were create in the main function?

What i mean is:
i've create a sf::RectangleShape rect(sf::Vector2f(22,22));
In the main function, however i want to call that specific rect object into another function called
void collissionDectection(){}.

How can i call for it? Or must i declare every Object and use all its arguments and members (all that mumbo jumbo) within the same function? Or should i use class? I rather use function, so any help is appreciated!

(I'm a beginner in C++, been studying and writting c++ code for over 3 weeks. However, i have previous programming knowledge, java and C#)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Lost in the basics of Function?
« Reply #1 on: May 13, 2014, 08:10:10 am »
You should use a class instead of free functions, that way you can have certain variables as member variables and don't need to pass them around.
However if you just want to pass something, you add it to the function declaration and if you want to change the specific object, you should pass it by reference.

Anyways if you have trouble understanding these very basic C++ or even general programming problems, you definitely spend more time reading a good book, e.g. one from this list: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Lost in the basics of Function?
« Reply #2 on: May 13, 2014, 07:22:48 pm »
yeah i understand classes, so i'll just use classes rather than functions. Thank you for the quick response !

 

anything