Understanding the weird syntax with curly braces in a constructor initializer list

后端 未结 3 1008
情书的邮戳
情书的邮戳 2020-12-16 09:45

So I was just browsing the source code of a library when I encountered this.

Font::Font(const sf::Font& font) :
        m_font{std::make_shared

        
3条回答
  •  爱一瞬间的悲伤
    2020-12-16 09:54

    That is a list initialization aka brace initializer list. More specifically, in this case it's a direct-list initialization.

    Basically the m_font variable is initialized with the value that's given in the curly braces, in this case it's initialized to a shared_ptr for the font object that's given to the constructor.

提交回复
热议问题