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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - KthulhuHimself

Pages: [1]
1
Window / Re: Help required with windows and classes
« on: March 29, 2017, 05:01:59 pm »
Hi

Please note that this is the SFML forum, we try to avoid generic C++ problems as much as possible. There are many better places where you can ask this kind of questions (stackoverflow, ...) ;)

The solution is simple: if your function needs to access a variable that it doesn't know, pass it as an argument.

void draw(sf::RenderTarget& target) // sf::RenderTarget is the base class of sf::RenderWindow
{
    target.draw(...);
}

int main()
{
    sf::RenderWindow window;
    draw(window);
}

Thanks a lot! This worked perfectly!

Oh, and don't worry, next time I'll find something slightly more sfml related to ask about.  ;)

2
Window / Help required with windows and classes
« on: March 29, 2017, 11:12:58 am »
Alright, so I know that this may seem a beginner's problem to the most of you, and I am indeed a beginner when it comes to sfml and C++ as a whole; but with that being said, I didn't manage to find a solution to this problem anywhere else.

It's a pretty simple problem:

Let's suppose I have my main(), where I render some window named "window".

Now I create a class (I use visual studio), in which I want to have one of the member functions draw something in the window. If I add the line "window.draw(sprite);" to the function in the class, this obviously generates the error "Identifier 'window' not declared".

So I ask: How am I supposed to have my member function draw something in the main()'s "window"?

I thank you all in advance.

Pages: [1]
anything