Virtual functions in constructors, why do languages differ?

前端 未结 6 1533
攒了一身酷
攒了一身酷 2021-01-04 09:56

In C++ when a virtual function is called from within a constructor it doesn\'t behave like a virtual function.

I think everyone who encountered this behavior for the

6条回答
  •  萌比男神i
    2021-01-04 10:20

    I think C++ offers the best semantics in terms of having the 'most correct' behavior ... however it is more work for the compiler and the code is definitiely non-intuitive to someone reading it later.

    With the .NET approach the function must be very limited not to rely on any derived object state.

提交回复
热议问题