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

Author Topic: Syntax Help  (Read 1486 times)

0 Members and 1 Guest are viewing this topic.

sirchick

  • Newbie
  • *
  • Posts: 13
    • View Profile
Syntax Help
« on: November 10, 2012, 06:19:17 am »
Hey

I need help with assign my window as a global with video mode. I can't seem to get the syntax correct.


I get this error:

Code: [Select]
error C2665: 'sf::VideoMode::VideoMode' : none of the 3 overloads could convert all the argument types
Not sure what i have to do to correct it. This is my script:

globals.h && globals.cpp:

//globals.cpp
#include <SFML/Graphics.hpp>
#include <string>

using namespace std;

std::unique_ptr<sf::RenderWindow> window;

//globals.h
#include <SFML/Graphics.hpp>

extern sf::RenderWindow* window;
 


Then my main.cpp has:

#include <SFML/Graphics.hpp>
#include <string>

using namespace std;

#include "globals.h"

int main()
 {


         window( new sf::RenderWindow( sf::VideoMode( (800,600,32), "Test") ) );

 

What am i doing wrong?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Syntax Help
« Reply #1 on: November 10, 2012, 02:02:18 pm »
What am i doing wrong?
I'd say everything... :-\

First don't use global object and second a unique_ptr does not equal a raw pointer, thus you extern sf::RenderWindow* window; doesn't make any sense.

For the actual compiler error the problem is obvious if you'd look at your code. Here I've colored your brackets:
window( new sf::RenderWindow( sf::VideoMode( (800,600,32), "Test") ) );

A way better design would be to use a class:

Application.hpp
#include <SFML/Graphics.hpp>

class Application
{
public:
    Application();
    void run();

private:
    void update();
    void draw();

private:
    sf::RenderWindow m_window;
};

Application.cpp
#include "Application.hpp"

Application::Application() :
    m_window(sf::VideoMode(800, 600), "Test")
{

}

void Application::run()
{
    while(m_window.isOpen()
    {
        update();
        draw();
    }
}

void Application::update()
{
    sf::Event event;
    while(m_window.pollEvent(event))
    {
        if(event.type == sf::Event::Closed)
            m_window.close();
    }
}

void Application::draw()
{
    m_window.clear();
    m_window.display();
}
 

Main.cpp
#include "Application.hpp"

int main()
{
    Application app;
    app.run();
}
 

AS you can see no need for any globals and everything is wrapped into a nice class.
« Last Edit: November 10, 2012, 02:04:24 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sirchick

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Syntax Help
« Reply #2 on: November 11, 2012, 06:45:47 am »
Thanks i'll have a fiddle with it and see what i can do :D