Reputation: 745
Visual Studio is giving me an odd error when running my C++ program. I even copied and pasted the code from SFML's website, but for some reason after window (sf::VideoMode Visual Studio says "Eror, expected a ')'". When I run the program, it gives error C2226 on line 8 (the render window one). What am I missing?
#pragma once
#include "SFML/Graphics.hpp"
#include "SFML/Window.hpp"
class AirportGame {
private:
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window"); // This line
public:
void init();
void tick();
void render();
int main();
};
Upvotes: 0
Views: 13058
Reputation: 77304
You cannot have a constructor call in your variable declaration. You will need to use an initializer list or make your RenderWindow variable a pointer and create the instance in your constructor with new
. Don't forget to delete
it in the destructor or use a smart pointer like std::unique_ptr
from the start.
While we are at at, your main
method won't work this way. It needs to be a free function, not a class method.
Upvotes: 2
Reputation: 5963
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window"); // This line
Is this the same as TYPE function(function(arg, arg), arg); ?
Can you have functions sitting there in class definitions like that? I think it expects a ) after window(
I think it needs to go in the functionality section of your code
Upvotes: 2