Thinking in c++中的问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 17:26:27
These exercises will take you step-by-step through the traps of MI. Create a
base class X with a single constructor that takes an int argument and a
member function f( ), that takes no arguments and returns void. Now inherit
X into Y and Z, creating constructors for each of them that takes a single
int argument. Now multiply inherit Y and Z into A. Create an object of
class A, and call f( ) for that object. Fix the problem with explicit
disambiguation.
大体是继承类,但是英语不过关,不知道具体的意思。。。。。
求达人帮忙。。。。

翻译:
这些练习将带你一步步经过多继承的困惑。创建一个基类X,他有一个带int参数的构造函数,一个无参数返回类型为void的成员函数f()。现在创建Y和Z两个类,继承于X,他们的构造函数都有一个int参数。现在有Y和Z派生一个A类,创建A的一个对象,通过这个对象调用f()函数。通过明确的无歧义性来改正这个问题。

首先这个程序会有问题,是多继承的二义性问题,可以通过将Y和Z虚继承于X来解决,即class Y :vitual public X和class Z :vitual public X

这些练习会让你一步步的跨越MI陷阱。创建一个基类X,要求它只有一个参数的构造函数,构造函数带有一个int类型的参数,同时创建按一个成员函数f(),f()不带参数,其返回值也为空。现在,建立2个派生于X的类Y、Z,Y和Z同样各自拥有一个只带一个int类型参数的构造函数。接着,从Y和Z多重派生出一个类A。创建一个A类的对象,并用该对象调用f()函数。明确地的修复这个问题。
//今天心情好,给你翻译下,没多少咱这种好心人了~