EECE3326_Jan23_2014 - Operator overloading w/ global functions, class member functions, overloading rules, dynamic memory allocation

2 Pages

Electrical and Comp Engineering
Course Code
EECE 2560
Waleed Meleis

This preview shows 80% of the first page. Sign up to view the full 2 pages of the document.
Introduction to C++ 1/23 Operator overloading with global functions bool operator == (const time24 &lhs, const time24 &rhs) { return lhs.hour == rhs.hour && lhs.minute == rhs.minute; // this is a good example of something we CAN do } //Assignment operators, e.g. t1 = t2; if not overloaded, default memberwise assignment is performed. // but we CANNOT overload the assignment operator with a global function //Consider assignment of ints //1 = x ; the left-hand operand must be an object. So this would compile if overloading with global functions were allowed. // Instead, we must overload the assignment operator with a class member function. Operator overloading with class member functions lhs op rhs; // returnType lhsClassName :: operator op ( type rhs ) bool time24:: operator == (const time24 &rhs) { return ( hour == rhs.hour) && (minute == rhs.minute); // we’re in the 24class, i.e. self or this, so we can access hour and minute } time24 &time24 :: operator = (const time24 &rhs) { hour = rhs.hour; minute = rhs.minute; return *this // this is a pointer to the call
More Less
Unlock Document

Only 80% of the first page are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.