On Feb 23, 10:52*am, "Paul" <pchris...@yahoo.co.uk> wrote:
> " Tiib" <oot...@hot.ee> wrote in message
>
> news:feef80b6-5cfe-47d0-a6d4-...
> <snip headers>
>
>
>
>
>
> > >> -- But in the
> > >> --other thread, you were looking for things that would make
> > >> --member functions fundamentally different from non-members.
>
> > >> I'm not looking for something to make them different , I know they are
> > >> different. I'm trying to understand why you think it's beneficial to
> > >> think
> > >> of them as the the same.
>
> > > --But they are logically same. For example when i see two lines of code:
>
> > > -- bag1.sort();
> > > -- sort( bag2 );
>
> > > --Should i think that different things happened to bag1 and bag2? Nope.
> > > --I only think that both objects got sorted, only that sorting
> > > --functionality was delivered syntactically differently by interface of
> > > --their classes. Also i see nothing why to call one of them OOP and
> > > --other non-OOP.
>
> > > The obvious difference in the above is:
> > > bag1.sort() /*sort is a member function of bag 1*/
> > > sort(bag2) /*sort is not a memeber function*/
>
> > > Inside the member function we have access to the this pointer. The term
> > > "this" suggests an object identity. The following does not work:
> > > void sort(){
> > > overwrite the object 'this' points to; (with _thiscall: mov ecx, 0 would
> > > do it)
> > > call thisfunction; /*'this' == ?? */
> > > }
>
> > > Normal sort() does not have a this pointer , there is no similar object
> > > identity. Within normal sort() the object passed as a parameter has no
> > > control over the lifetime of the function.
> > > The following applies for the normal sort() function:
> > > void sort(anObject){
> > > overwrite anObject ;
> > > call thisfunction(anObject) ; /* anObject is OK, it contains what we
> > > overwrit it with*/
> > > }
>
> > You did not comment on this, do you understand what I am explaining?
>
> --Yes, i understand. For me both the functions are part of A's
> --interface:
> --void A:
neOperation() {/* code operating on this */}
> --void otherOperation( A& that ) {/* code operating on that */}
>
> --What is the big matter if there is pointer "this" or reference "that"?
> --The otherOperation() is even more OOP for me since it accesses only
> --public interface of class A and does not mess with dirty inner
> --details. So i know that if i for some performance reasons have to
> --refactor implementation details of A leaving its public interface same
> --then i don't need to modify otherOperation (or tests written for it).
>
> Forgetting about operator oveloading , I am talking about what sort()
> initially seemed to be proposed as, specifically:
> anObj.sort(); /*A member function of anObject*/
> sort(anObj) /*A normal function with 'this' passed explicitly as a
> parameter*/
>
> The difference is the possible sequences of execution given the following
> scenario of recursion.
>
> sort(){
> * * this = new anObjType; /*replace the object the function belongsto*/
> * * (*this).sort(); */*re-invoke this function is not possible, what does
> 'this' point to?*/
> }
Does not compile. What compiles is:
void T::sort()
{
*this = T();
sort();
}
Why you brought it up? It is endless recursion that crashes when stack
is full.
> sort(anObj){
> * * anObj = new anObjTye; /*replacing the object( heap or stack whatever,
> the code is psuedo)*/
> * * pointertothisfunction(anObj) /*Ok to call this function, recursion is ok
> with a new object.*/
>
> }
Again does not compile. Compiles something like:
void sort( T& anObj )
{
anobj = T();
sort( anObj );
}
Still endless recursion.
> The member function version does not have the same possible sequences of
> execution as the normal version.
> The member function version has an object identity, it belongs to the object
> on which it is called.
I am maybe idiot or my English lacks but i can't parse what you say
here. The functions are equal for me only syntax of calling is
different.