• entries
    146
  • comments
    436
  • views
    197482

Quiz Answers

Sign in to follow this  
Washu

130 views

Quiz answers:
During the construction of a const object, if the value of the object or any of its sub objects are accessed through an lvalue that is not obtained, either directly or indirectly, from the constructor's this pointer, the value of the object or sub object thus obtained is unspecified. As such the answers to questions 1, 2 and 3 are:
1. i will contain an unspecified value as obj.c results in an unspecified value.
2. After the evaluation of the second numbered line, p->c will contain the unspecified value that was in i.
3. The unspecified value in obj.c will be printed.

At most only a single user defined conversion (constructor or conversion function) is implicitly applied to a single value. As such the answers for questions 4 and 5 are:
4. This should result in a compile time error.
5. The type is explicitly converted to type X using a conversion constructor, and operator int() will be called on that X type, resulting in the int containing the integral value returned by X::operator int()

An explicit constructor constructs objects only where the direct-initialization syntax or casts are explicitly used. As such the answer for question 6 is:
6. The first numbered line will result in an error, the second numbered line will result in z2 being assigned the value in an unnamed temporary constructed during the static cast.

A typedef-name that names a class shall not be used as the identifier in the declarator for a destructor declaration. As such the answer to question 7 is:
7. The results of the calls on the numbered lines, irrespective of the other lines are.
a. Calls Base::~Base()
b. Calls Derived::~Derived()
c. Calls Derived::~Derived()
d. Calls Base::~Base()
e. This line should result in an error as this is clearly a decleration of a destructor (used in a function call syntax). As such the usage of the typedef is illegal. However it has been noted that many compilers will accept this syntax as legal. That does not mean that you should do it, nor expect it to work correctly.
Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now