[cs13001] Lab 9 question

Mikhail Nesterenko mikhail at cs.kent.edu
Tue Apr 5 13:02:41 EDT 2016


> Thanks, syntax question: on slide 9 of structures lecture you ask " how to
> access char of string?"
> Is it: as[3].b[2] or (as[3].b)[2] for letter L in "Hello".

as[3].b[2] is correct.

> 
> Slide on Friend functions last line: what does it mean "Objects are used
> symmetrically"?
> 

Alternatively (without a friend function), the equal() function may be
coded as a member function. Then, the invocation would be

      date1.equal(date2)

That is, the member function of date1 compares the state of date1 to
the state of date2. However, in this case, the two objects are
accessed differently (one through a member function, the other as a
parameter). This runs counter to the intent of "equal" function that
just compares the states of two objects. The implementation is more
intuitive with a fried function where the invocation is:

      equal(date1, date2)

That is, the two objects are accessed as parameters.


> Clarification for me;

> 
> 1.  Does a void constructor with an empty body (no code to initialize any
> member variable)  automatically initialize member variables to a default
> value or values are same as when no constructor (junk values)?

If a void constructor does not explicitly assign a value to a member
variable, then the value of this member variable is arbitrary.

Thanks,
--
Mikhail


More information about the cs13001 mailing list