在类名之后但在中括号之前加引号
quotes after the class name but before open brackets
我有一个简单的问题想不通。我没有写这个代码。我知道tetromino_和moveTime_是两个不同类的实例。我的问题是,为什么它们在括号外声明,但仍然在类内。这个实例声明方法有名称吗?
Game::Game() :
tetromino_{ static_cast <Tetromino::Type>(rand() % 7) },
moveTime_{ SDL_GetTicks() }
{
//srand(time(NULL));
//initialize SDL and if it fails, present an error
if (SDL_Init(SDL_INIT_VIDEO) != 0){
throw std::runtime_error("_Init(SDL_INIT_VIDEO)");
}
//width of thhe window is 650/2 and the height is 650
SDL_CreateWindowAndRenderer(650 / 2, 650, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS, &window_, &renderer_);
//set the window position
SDL_SetWindowPosition(window_, 365, 1);
}
如果我的问题不清楚,这叫什么
Game::Game() :
tetromino_{ static_cast <Tetromino::Type>(rand() % 7) },
moveTime_{ SDL_GetTicks() }
{
这只是一个构造函数。
Game::Game
构造函数正在构造类的两个成员tetromino_
和moveTime_
。大括号(而非括号)是统一的初始化语法,它是C++11/C++14的新语法。
相关文章:
- 为什么在popback()操作之后,它仍然打印完整的矢量
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 在类定义之后定义一个私有方法
- 在循环C++中指定字符串之后,不会打印该字符串
- C++宏忽略之后的内容
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 我提出什么条件才能再加5%的折扣
- strncpy之后的char数组的错误行为
- 如何在fixup_bundle宏之后修复"即使找到Qt平台插件也无法加载" " "xcb" Qt平台插件"?
- 从 *.lib 加载 *.dll 并在之后使用此库生成 *exe:可能吗?
- 在类名之后但在中括号之前加引号
- 在每个新行之后再加一个空格
- 如何使用L前缀作为未加引号的字符串
- getline用于逗号分隔的表文件,在某些字段周围加引号