[cs13001] Purpose of some parts of code.

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Dec 7 17:07:42 EST 2012


> 
> You said in the final lecture that it's important to not only know
> what a code does, but also what is it's purpose, so I wanted to ask
> you a few questions.
> 
> What is the purpose of a copy constructor?

A copy constructor a function that is invoked automatically when a
copy of an object is being made: when passing an object by value or
when returning an object. A copy constructor explicitly specify how a
copy of the object should be made. It is useful in case the object
contains dynamically allocated members.

> 
> Why do we need the big three? What would happen without them?

The big three (copy constructor, destructor, and overloaded
assignment) are needed to ensure that operations such as assignment
operate correctly for objects with dynamically allocated members.


> When using an Exception, do I just wrote the same code as I would
> normally and put it in a try block, while adding the throw part?

exceptions are a mechanism of handling extraordinary situations such
as division by zero uninitialized pointers, failure of memory
allocation, etc.


> What exactly is an iterator?

Iterator is an abstract construct that is made to behave like a
pointer and is usually implemented using pointers. However it may be
significantly more sophisticated. For example, an iterator may be used
to traverse a search tree. You'll study iterators in greater detail in
CSII


> What is the difference between a dereference and a pointer? I though
> * was a pointer, if it's not, what exactly is the pointer?

Dereference is an operation, a pointer is a variable type. A pointer
is a variable that stores an address of a memory location.

Thanks,
-- 
Mikhail


More information about the cs13001 mailing list