小编him*_*ims的帖子

防止C++中的多重继承

最近我参加了一次C++技术访谈:在那次采访中我问了一个我无法回答的问题:即使我尝试上网和一些论坛但无法得到答案,请参阅下面的代码片段:

using namespace std;

class Base1
{
    public:
    Base1() 
    {
        cout << "Base1 constructor..." << endl;
    }

    ~Base1() 
    {
        cout << "Base1 Destructor..." << endl;
    }
};  

class Base2
{
public:
    Base2() 
    {
        cout << "Base2 constructor..." << endl;
    }

    ~Base2() 
    {
      cout << "Base2 Destructor..." << endl;  
    }
};

class Derived : public Base1, public Base2 
{
public:
  Derived()
  {
      cout << "Derived constructor...."  << endl;
  }
  ~Derived()
  {
      cout << "Derived Destructor..." << endl;
   }
};


int main() …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance multiple-inheritance

15
推荐指数
1
解决办法
2222
查看次数

dynamic_cast如何在内部工作?

有人可以解释一下dynamic_cast内部是如何工作的吗?虚拟指针的作用是什么?

c++ rtti

3
推荐指数
1
解决办法
3575
查看次数

标签 统计

c++ ×2

inheritance ×1

multiple-inheritance ×1

rtti ×1