从类返回渲染窗口

时间:2012-11-09 23:16:29

标签: c++ sfml

我对我如何从类中返回渲染窗口感到有些困惑,不确定我的返回类型是错误还是语法或两者都有!

我的main.cpp有:

Window Render(800, 600, "Test");
sf::RenderWindow window = Render.Init();

我的课程是:

        Window::Window(int x, int y, std::string title){
            ResoX = x;
            ResoY = y;
            Title = title;
        }

    sf::RenderWindow Window::Init(){
        return screen(sf::VideoMode(ResoX,ResoY,Title));
    }

班级的标题:

class Window
{
    private:
        int ResoX, ResoY;            
        std::string Title;
        sf::RenderWindow screen;
    public:
    Window(int, int, std::string);

    sf::RenderWindow Init();
};

我的错误是:

error C2665: 'sf::VideoMode::VideoMode' : none of the 3 overloads could convert all the argument types could be 'sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)' while trying to match the argument list '(int, int, std::string)'

error C2064: term does not evaluate to a function taking 1 arguments

有人知道我如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

来自SFML文件( http://www.sfml-dev.org/documentation/1.6/classsf_1_1VideoMode.php#a9478572db06121f70260e6b9dc21704e

sf :: VideoMode构造函数声明为:

sf::VideoMode::VideoMode(unsigned int   ModeWidth,
                         unsigned int   ModeHeight,
                         unsigned int   ModeBpp = 32 
                         )  

表示你不能将第3个参数作为字符串传递,你可以调用它:

return screen(sf::VideoMode(ResoX,ResoY));