Kevin Brosius on 22 Oct 2003 18:25:02 -0400 |
> > > 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 ? Shhh. It's a teaching example and helps get them thinking about optimization. :) > The mess like MDBuilder when I got ? <g> [ This is for Kevin eyes only ] You escaped that, I'm happy to say. Lucky us. I'm fixing something in there now. > 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. Yes, of course you're right. It was more an example to point out what might happen. I would question use of a member function that didn't access member data myself. -- Kevin ___________________________________________________________________________ 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
|
|