简体   繁体   中英

Expected Expression in C++, but I can't find the error

I recently bought a book called "SFML Game Development by Example" and the code is giving me some problems.

Here is the line giving me trouble:

m_window.create({ m_windowSize.x, m_windowSize.y, 32 }, m_windowTitle, style);

Where the bracket meets the curly brace ({ it tells me that there is an expected expression.

Here is the code for the entire file

#include "Window.h"

Window::Window(){
    Setup("Window", sf::Vector2u(640, 480));
}

Window::Window(const std::string& l_title, const sf::Vector2u& l_size){
    Setup(l_title, l_size);
}

Window::~Window(){
    Destroy();
}

void Window::Setup(const std::string& l_title, const sf::Vector2u& l_size){
    m_windowTitle = l_title;
    m_windowSize = l_size;
    m_isFullscreen = false;
    m_isDone = false;
    Create();
}

void Window::Create(){
    auto style = (m_isFullscreen ? sf::Style::Fullscreen : sf::Style::Default);
    m_window.create({ m_windowSize.x, m_windowSize.y, 32 }, m_windowTitle, style);
}

void Window::Destroy(){
    m_window.close();
}

void Window::Update(){
    sf::Event event;
    while(m_window.pollEvent(event)){
        if(event.type == sf::Event::Closed){
            m_isDone = true;
        }else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F5){
            ToggleFullscreen();
        }
    }
}

void Window::ToggleFullscreen(){
    m_isFullscreen = !m_isFullscreen;
    Destroy();
    Create();
}

void Window::BeginDraw(){
    m_window.clear(sf::Color::Black);
}

void Window::EndDraw(){
    m_window.display();
}

bool Window::IsDone(){
    return m_isDone;
}

bool Window::IsFullscreen(){
    return m_isFullscreen;
}

sf::Vector2u Window::GetWindowSize(){
    return m_windowSize;
}

void Window::Draw(sf::Drawable& l_drawable){
    m_window.draw(l_drawable);
}

I've done everything I can think of. I've even downloaded the source code from the book's website, Ive checked the books errata to see if there should have been a change. Other people working on this book seem to have no problem at this part and the fact that downloading the source code still gives me the error makes me think it has something to do with me, but what?

Your code requires support for C++ 11 features that your compiler doesn't support. See the C++11 features list for VS2012. Upgrade to a more recent version that fully supports C++11 if you want to compile C++11 code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM