将我的窗口设置为C 类

Set my window in a class c++

本文关键字:设置 我的 窗口      更新时间:2023-10-16

我不知道为什么,但是在课堂中创建窗口时会遇到错误。

错误是:

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

我不了解其原因,负责的班级是班级的构造函数:

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
}

我的标题window.h在私有设置为:

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

我的main.cpp像这样设置了它:

Application game(setting,style);

这可能是什么原因?

使用成员初始化器来初始化您的成员:

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

它称为成员初始化器列表。成员初始化器列表组成在逗号分隔的初始化列表之前,先于结肠。它放置在关闭之后参数列表的括号和函数主体的开头括号之前。