Studydroid is shutting down on January 1st, 2019

Bookmark and Share

Front Back
What are some significant differences between pointers and references?
References cannot be set to null.� A reference's value cannot be changed.
What are some of the problems with c-style casts?
Since the syntax is common, they are hard to find, and they are not very specific about the intent of the cast.
How does the functional behavior of pre-increment and post-increment differ?
Post-increment must increment itself and then return a temporary containing its old value.� Pre-increment simply increments and returns itself.
When is it guaranteed pre-increment is more efficient than post-increment?
When incrementing anything other than a built-in type.
Why is it unwise to overload the &&, ||, and , operators?
The default implementation of these operators perform "short-circuit" evalutation.  It is impossible to duplicate this behavior in a user defined function.� Therefore, more may� be assumed of the implementation than provided.
Why is it wise to put all de-allocation code in the destructor?
When an exception is thrown, the destructor for local objects are called, giving the opportunity to prevent memory leaks.
In an exception, how is the parameter ultimately passed?
By value.
If a reference to a base class is used as the parameter in an exception, what type will the catch recieve?
The base class type.
When re-throwing an exception inside of an exception handler, why is it wise to use throw; instead of throw ;?
throw ; will incur a copy call.
When deciding which virtual function or exception handler to call, how are functions and exception handlers treated differently?
Virtual functions are chosen on "best fit".Exception handlers are chosen on "first fit".
Why is it dangerous to use a pointer as the exception parameter?
Because it could be a pointer to a local object that has been destroyed.
Why is it poor form to "catch-on-value"?
Doing this performs two copy operations, and could result in object slicing.
Which is it best to use as an exception parameter: value, pointer, reference?
What is a potential problem with using exception specifications?
If an exception handler is added without adding it to the specification, when the exception is thrown, unexpected will be called, which calls terminate, which ultimately calls abort.
Should the use of exception handling be limited?
Yes, there is signifigant overhead in handling exceptions.
What is the 80-20 rule?
For every resource, only 20% of the code has an impact on the resource.�

This has been repeatedly verified through countless examinations of machines, operating systems, and applications that this is true for resources such as runtime, memory, and disc access.

What is "lazy-evaluation"?
Not performing an operation until absolutely necessary.
what is the benifit of using:

return int(5);


return 5; ?
This is called "the return value optimization", and is often implemented by compilers.  return 5; incurs the creation of two temporary variables.  The first is created and initialized using the value "5", the second is created as the return value.  Using "the return value optimization" technique, the compiler can eliminate the creation of both temporary variables.
How can you prevent an implicit type conversion for a function?
Overload the function using the undesired type, and throw an exception when encountered.
Why would operator += be more efficient than using operator + and operator = separately?
Temporaries are created for return values.  By combining them into one function call, the creation of a temporary is eliminated.
What may be the deciding factor on whether or not to use C+= iostream library or C stdio library?
iostream is more robust, but slower than stdio.
What are some of the costs of using virtual functions?
They cannot be inline, and the use of a virtual table requires memory for storage and cycles for lookup.
What is RTTI and how is it used?
"Run Time Type Information".  An object of type "type_info" will be returned when executing a function's typeid operator.
can an inherited virtual function ever return a type other than what is specified in the base class's declaration of the function?
Yes, if the return type is a pointer (or reference), and the type returned is derived from the return type of the base class.
How would you find out if T is of type float?
typeid(float) == typeid(T)
How is type info typically stored for RTTI?
As a type_info object with the address is stored in the v-table.
What is a "virtual constructor", and what design pattern is it associated with?
It is a virtual function in a parent class, often named Clone, that returns a pointer (or reference) of it's own type.  The derived classes decide what derived type of the parent class to return.

This is also known as the "Factory Method" creational design pattern.
What is the copy constructor?
The constructor that takes as a parameter a constant reference (or pointer) to an object of the same type.
x of y cards