早教吧 育儿知识 作业答案 考试题库 百科 知识分享

英文更佳1.WhatdoesinheritancemeaninC++?SupposeyouhaveclassAandclassB,underwhichofthefollowingtwoconditionsclassBshouldinheritfromclass(1)AisapartofB.(2)BisakindofA.2.Whenshouldthekeywordvirtualbepl

题目详情
英文更佳
1.What does inheritance mean in C++?Suppose you have class A and class B,under which of the following two conditions class B should inherit from class
(1)A is a part of B.
(2)B is a kind of A.
2.When should the keyword virtual be placed before a member function of a class?Do all of the virtual member functions have to be overridden in the derived class?If not,why?
3.Does C++ support multiple inheritance?Some people think that multiple inheritance can cause a variety of ambiguity problems.Try to explain what problems will multiple inheritance cause and how to avoid them.
3.What operators cannot be overloaded in C++?What restriction applies to overloading the following operators?
=,( ),[ ],and ->.
cout








▼优质解答
答案和解析
1、(2),B是A的特例,因为B有A的非静态方法和成员
2、virtual public Class A{} publicvirtual Class A{} virtual void print().
对于不需要virtual void print() const=0;的定义,如果没有重载,继承的类或者函数依然是virtual函数,需要在其某个后代中完全被重载才可以直接实例化,否则不能用.
3、有、会、解决方法C obj;obj.A::func();
3、C/C++ 里大多数运算符都可以在 C++ 中被重载.只有 . 和 ? :和::和.*不可被重载,此外 sizeof()也不可以被重载.限制是:该组重载函数中任何两个都必须有不同的参量表.具有相同类型参量表、仅在返回值类型上不同的重载函数会引起错误.