Sergey Ostrovsky on 22 Oct 2003 10:46:02 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Re:[PLUG] C++/*this


</snip>

> Well, you might want to think of it from a usage standpoint.  I think
> you'll find that the functions don't always need a *this pointer.  It
> depends on the implementation.  For example:
> 
>       class Foo {
> 
>          public:
>             void print(void) { printf("Hello World"); };
>       };
> 
> If I call an instance of the above, what happens?
> 
>    Foo foo;
>    foo.print();
> 
> I'd bet most recent compilers don't pass *this for the above case.  It's
> unneeded for the implementation.

</snip>

I don't think it's an interesting case.
If you don't need "this", why to make it a member function ? What gives ?
The mess like MDBuilder when I got ? <g> [ This is for Kevin eyes only ]
The core idea of C++ ( if I got Mr Stroustrup right, of course )
is to tie a set of data ( structure ) to functions using this data.
So how do we conveniently give such functions the reference to data ?
Simply introducing the implicit first calling parameter "this".
And the data is protected on language level from accessing from outside,
because only such member functions are given access to it.
There're cases when you don't need access to a particular instance.
Static member functions and friends exist just for this

Sergey.

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug