// gamewindow.hpp
#include <SFML/Graphics.hpp>
#include <string>
#include <cstdint>
class GameWindow : public sf::RenderWindow
{
public:
GameWindow(const uint32_t&, const uint32_t&, const std::string&);
void toggleFullscreen();
static const ResolutionSetting w640h480,
w1600h900,
w1920h1080,
w2560h1440;
private:
class ResolutionSetting
{
public:
ResolutionSetting(const uint32_t& width, const uint32_t& height)
: res(width, height) {}
private:
sf::Vector2u res;
};
std::string _title;
uint32_t _width;
uint32_t _height;
};
我試圖在GameWindow
類,其中ResolutionSetting
類被定義爲一個private
類中GameWindow
內初始化公共ResolutionSetting
對象。初始化類的靜態常量成員,其中成員是私有類型?
我看到this交詳細介紹瞭如何初始化類static
const
構件,但是這不包括的情況下,當所述部件的類型定義爲從外部類範圍(被指定的類型,當諸如不可訪問與private
訪問規則)。
我該如何去初始化這些對象?請問:
const GameWindow::ResolutionSetting GameWindow::w640h480(640, 480);
或
const GameWindow::ResolutionSetting GameWindow::w640h480 = GameWindow::ResolutionSetting(640, 480);
就夠了? (假設我可以更正ResolutionSetting
無法訪問的任何可能的問題)。