2012-11-09 105 views
0

我有點卡住了我如何從我的類返回我的渲染窗口,不知道如果我有返回類型錯誤或語法或兩者兼而有之!從類返回渲染窗口

我的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

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

SF :::視頻模式構造函數聲明爲:

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

這意味着你可以不通過第三個參數爲字符串,你可以把它叫做:

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

啊!這工作!謝謝 ! – Sir