Diamond of death and Scope resolution operator (c++)

后端 未结 3 532
遇见更好的自我
遇见更好的自我 2021-01-11 10:55

I have this code (diamond problem):

#include 
using namespace std;

struct Top
{
    void print() { cout << \"Top::print()\" << e         


        
3条回答
  •  青春惊慌失措
    2021-01-11 11:36

    Actually, giving code is working fine as I tried it on Visual Studio 2019. There are two way to solve Diamond Problem; - Using Scope resolution operator - Inherit base class as virtual

    Calling print function by b.Right::Top::print() should be executed with no errors. But there is still two objects of your base class (Top) referred from your Bottom class.

    You can find additional detail in here

提交回复
热议问题