operator overloading

Mar 15, 2011 at 10:56am
1-what is the difference or the pros of using dynamic allocated array (using new) over typical array?

2-in the next ex.
Date &Date::operator==(const Date & mydate1)
this binary operator takes two objects to compare
mydate1, mydate2
if i am using *this pointer in the body of the prescribed fuction, to whom is the pointer points mydate1 or mydate2?
Mar 15, 2011 at 11:21am
1 - allocating memory dynamically is both slower and less safe than allocating on the stack, only allocate dynamically when you have to.

2 - the this pointer is a pointer to the current object being acted upon, if you've overloaded the equality operator on your Date class and you have two dates

1
2
Date date1(1,5,2010);
Date date2(15,3,2011);


then you do this

 
if ( date1 == date2 )


that is equivalent to

 
if ( date1.operator==(date2) )


and the this pointer would point to date1
Last edited on Mar 15, 2011 at 11:46am
Mar 15, 2011 at 11:25am
thank u
Last edited on Mar 15, 2011 at 11:34am
Topic archived. No new replies allowed.