I found some questions in a C++ book and there is no provided solutions to these questions. These questions sort of confuse me and I wondering if someone help me answer these questions. This is not an assignment but for learning purposes.
1) C++ adds ______ new cast operators in addition to C's casting operator.
(a) 0 (b) 1 (c) 2 (d) 3 (e) 4 (f) 5
I believe this is 4. The static cast, dynamic cast, reinterpret cast and the const cast.
------------------------------------------------------------------------------------------------------------------
Q2) To behave like Java and other object-oriented languages, one needs to make all inheritance
________.
(a) public (b) protected (c) private (d) virtual (e) non-virtual
Public?
-------------------------------------------------------------------------------------------------------------------
Q3) To behave like Java and other object-oriented languages, one needs to make non-static
member functions _____.
(a) public (b) protected (c) private (d) virtual (e) non-virtual
Can't a non-static member function be all of the above? If not why?
--------------------------------------------------------------------------------------------------------
Q4) To catch any exception, one needs to fill in this catch(________) clause with:
(a) std::throwable& (b) std::exception& (c) ... (e) none of these
none of these
----------------------------------------------------------------------------------------------------------
Q5) To rethrow an exception that has just been caught, one would write this statement in the
catch clause's body:
Answer: __________________________
throw;
----------------------------------------------------------------------------------------------------------
Q6) The iostream's can be extended to support new stream devices by writing a class that
inherits from the class:
Answer: __________________________
Not sure.
--------------------------------------------------------------------------------------------------------------
Q7) The this pointer is a ____________ pointer to an object.
Answer: __________________________
I am not sure what they are looking for here. A special type of pointer?
Thanks.
3)
>> Can't a non-static member function be all of the above? If not why?
It can be all of the above, but to have the same behavior as Java, they need to be virtual to make sure that they're dynamically bound (which is what Java does for all non-static member functions).
What exactly do you mean by dynamically bound?