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

Author Topic: c++ question about using objects as function parameters and casting.  (Read 1716 times)

0 Members and 1 Guest are viewing this topic.

svladd Cjelik

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Hey everyone, and thanks in advance.
 
I know my question is not SFML specific, but more about C++, but I thought you may be able to help me anyways.
 
Part of my code is here https://gist.github.com/4123800
 
I have not included all the files, because the program is HUGE. It's a roguelike game ...and I have been working on the data for some time, and I am putting it together to render and play with for the first time now and my problem is with the drawFloor() function.

The call itself is right at the end of main().

I know I need to cast the objects and send the pointers as parameters, but I cannot find the correct syntax.

sf::Texture floortile1 ---can be found on line 9 of floorsprites.cpp sf::RenderWindow window ---can be found on line 39 of main.cpp

Also, I have left the two commas in the prototype, the call, and the function itself where my parameters need to go.

Again, thanks in advance.

Also, I will be here if anyone needs to see more code.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: c++ question about using objects as function parameters and casting.
« Reply #1 on: November 21, 2012, 10:57:47 am »
Well you should probably learn what a class is and how to use it. With that you can work around global variables or the problem of passing objects around for every function. In addition to that, you should also read about functions and function arguments.

You see we gladly like to help, but SFML just isn't a library for beginners, that nearly have no idea about C++. SFML needs some basic understand of C++, which includes classes and functions etc. And since there thousands of C++ programming books out there and most of them will explain these principles better than we can in many posts, I strongly advise you to get a book and read it. ;)

As I said, to 'solve' your problem, put everything into a class, define the texture and sprite as member variable and then you can access it from any member function. Also keep in mind that the current probably won't show anything on the screen, because you have to call clear(), draw(), display() and at the moment you only call draw(). Additionally you have to use a main/game loop if you want your application to continue to draw things instead of instantly closing (read the tutorials and/or look at the examples).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: c++ question about using objects as function parameters and casting.
« Reply #2 on: November 21, 2012, 12:05:03 pm »
Basically what eXpl0it3r says. Or type your question in Google and you'll have your answers. Be sure to check the sites www.cplusplus and stackoverflow.com, those should contain all your answers concerning c++.

svladd Cjelik

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: c++ question about using objects as function parameters and casting.
« Reply #3 on: November 23, 2012, 02:31:06 am »
Got it, thank you both for your help.
 
I simply put both the functions into a class, and created an object which I then passed about the place.
 
OO 101.