Answers to Homework Assignment 1

1. The difference between operator overloading as a member function and as a friend function are:
    a. Operator overloading as a member function has one argument less than as a friend function.
    b. The member function has access to the "this" pointer while a friend function may not use it.

2.   (a)        Class XYZZY
                   {
                        Private:
                                int X, Y, Z;
                        Public:
                                XYZZY (int a=1, b=2, c=3);
                                void setX (int value);
                                void setY (int value);
                                void setZ (int value);
                                int getX ( ) const;
                                int getY ( ) const;
                                int getZ ( ) const;
                                friend int F (const XYZZY& );
                    };
        (b)        Constructor
                    XYZZY::XYZZY (int a, int b, int c)
                                : X(a), Y(b), Z(c)
                    {
                            //no code
                    }
        (c)        int F (const XYZZY& param)
                    {
                        int m = param.X;
                        if (param.y < m)
                            m = param.Y;
                        if (param.Z < m)
                            m = param.Z;
                        return m;
                    }

3. a. Precedence, associativity, and number of arguments are preserved.
    b. Assignment, function calls, subscript, and pointer dereferencers MUST be number functions.
    c. Cannot create new operators.
    d. Operators: ".", "*", and "::" cannot be overloaded.
    e. Must have one user defined operand.
    The restrictions are imposed to limit the complexity of the compiler.

4. a. The copy constructor creates a copy of an existing object by taking its argument a reference to an object of the class.
    b. It's called when an object of the class is passed by value. Also when a function returns an object of the class, or when initialization an object to be a copy of another object of the same class.
    c. This is not correct. Because a reference argument is required rather than a pass by value argument.

5. Conversion constructors are constructors that take a single argument. They are used to convert built-in datatypes into the user-defined type.
    Conversion cast operators are the operators used to convert the user-defined type into another built-in datatypes. Both are called expictly or implicitly.