Not sure how to explain this...

These are my codes,

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/System/Vector2.hpp>
#include "resize.h"


int main(){
    sf::RenderWindow window(sf::VideoMode(500, 400), "Mouse Position", sf::Style::None);
    
    window.setVerticalSyncEnabled(true);
    
    while(window.isOpen()){
        sf::Event event;
        
        Resizable resizable;
        resizable.resize();



resize.h
1
2
3
4
5
6
7
8
9
10
#ifndef RESIZE_H
#define RESIZE_H


class Resizable{
    public:
        void resize();
};

#endif 



resize.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "resize.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/System/Vector2.hpp>
#include <iostream>


void Resizable::resize(){
    if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
        sf::Vector2i mPos = sf::Mouse::getPosition(window);
        sf::Vector2u wSize = window.getSize();
        window.setSize(sf::Vector2u(wSize.x + 1, wSize.y));
        std::cout << wSize.x << std::endl;
    }
}




Error occurs in sf::Vector2i mPos = sf::Mouse::getPosition(window);
window was not declared...which is declared in main.cpp

How do I fix this?

Last edited on
You should have Foo::doSomething() take an sf::Window by reference and then perform the resize upon it. However replacing a single line function with a single line function seems rather pointless.
I edited my code above using my actual project. Sorry about using example code.
Okay, from that there are several things you could do. You could have an sf::RenderWindow as a member of Resizeable, initialised during construction. You could pass the sf::RenderWindow by reference into Resizeable::resize(). Alternatively, you could turn Resizeable::resize() into a single standalone function as it doesn't appear to use anything from inside Resizeable.
Topic archived. No new replies allowed.