Avatar of saygapro
saygapro
 asked on

Questions about C++

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.
C++

Avatar of undefined
Last Comment
Infinity08

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Infinity08

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
saygapro

ASKER
Hi, thanks for helping me with the questions.

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?
Infinity08

>> What exactly do you mean by dynamically bound?

Exactly what virtual does ... The decision which (polymorphic) method has to be called is made at run time, not compile time.

More info here :

        http://www.parashift.com/c++-faq-lite/virtual-functions.html
Infinity08

I just noticed a typo :

        "Note that the const here applies to the const"

should have been :

        "Note that the const here applies to the pointer"

of course
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23