error C2797 : list initialization inside member initializer list

前端 未结 3 1208
日久生厌
日久生厌 2021-01-14 10:22

I was watching MVA\'s tutorial on C++ and the code I\'m mentioning below is written by Kate not me. However she seems to get around with it without compiling showing any err

3条回答
  •  温柔的废话
    2021-01-14 11:02

    There was a compiler change between the time James and I wrote the code we used for the MVA day and today. What's happening is that

     _name{ initial_name }
    

    is being interpreted as creating an initializer-list with one item in it and using that to initialize the member variable. Which you can't do.

    The fix is to switch to round brackets:

     _name(initial_name)
    

    This is causing confusion for a number of people and I have at least one client for whom this broke working code.

提交回复
热议问题