4

I have a simple question that i can't figure out. I did not write this code. I know that the tetromino_ and moveTime_ are instances of two different classes. My question is why are they declared outside the brackets but still within the class. Does this method of instance declaration have a name?

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);
}

In case my question was not clear, What is this called

Game::Game() :
tetromino_{ static_cast <Tetromino::Type>(rand() % 7) },
moveTime_{ SDL_GetTicks() }
{
Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
soso
  • 311
  • 1
  • 4
  • 13

1 Answers1

4

This is just a constructor.

The Game::Game constructor is constructing two members of the class, tetromino_ and moveTime_. The braces (not brackets) are the uniform initialization syntax which is new to C++11/C++14.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148