0

I don't know why but I'm getting an error when creating my window in a class.

The error is:

game.cpp(11): error C2064: term does not evaluate to a function taking 2 arguments

I'm not understanding the cause of this, the responsible is in the constructor for the class :

window.cpp

Application::Application(std::map<string,string>& s, std::map<string, string>& t){

settings = s;
theme = t;
window(sf::VideoMode(800, 600), "Test"); //error is here

}

In my header window.h is set up in private as:

private:
    std::map<string, string> settings;
    std::map<string, string> theme;
    sf::RenderWindow window;

My main.cpp sets it up like so:

Application game(setting,style);

What could be the cause of this ?

Sir
  • 8,135
  • 17
  • 83
  • 146

1 Answers1

2

Use member initializers to initialize your members :

Application::Application(std::map<string,string>& s, std::map<string, string>& t)
:settings(s),
 theme(t),
 window(sf::VideoMode(800, 600), "Test") 
{
}

It’s called a member initializer list.The member initializer list consists of a comma-separated list of initializers preceded by a colon. It’s placed after the closing parenthesis of the argument list and before the opening bracket of the function body.

billz
  • 44,644
  • 9
  • 83
  • 100
  • Wait why is it outside the curly brackets ? Ive done it via my question method up until now it used to work.. whats different about that method o_0 – Sir Nov 11 '12 at 06:32
  • can be useful link. http://stackoverflow.com/questions/7665021/c-member-initialization-list – billz Nov 11 '12 at 06:39
  • And this: http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor – chris Nov 11 '12 at 07:03