Virtual member call in a constructor

后端 未结 18 2154
[愿得一人]
[愿得一人] 2020-11-22 01:27

I\'m getting a warning from ReSharper about a call to a virtual member from my objects constructor.

Why would this be something not to do?

18条回答
  •  执笔经年
    2020-11-22 02:08

    Yes, it's generally bad to call virtual method in the constructor.

    At this point, the objet may not be fully constructed yet, and the invariants expected by methods may not hold yet.

提交回复
热议问题