| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: C++ |
From: Tony Williams
Geo wrote:
> "Peter Sawatzki" wrote in message
> news:MPG.1bf827b322d0373989741{at}news.barkto.com...
>
>
>>The main difference is that functions that operate on a class are
>>implicitly called with the self/this pointer as an invisible
"argument".
>
>
> Why is that distinction important?
Because it gives you an excellent way to use global variables under a
different name. Want to use a global but afraid of being mocked by language
lawyers? Stick it in an object and suddenly it's all ok.
Congratulations; you've managed to sneak the variable into just about every
function and nobody will ever find out where it's declared, let alone where
it's modified.
Seriously, it's a useful feature but is very easy to abuse. In a member
function, you can write
notAGlobalHonest = 1
but it can be clearer to write
this->notAGlobalHonest
Having said that, if you find yourself needing to use 'this' to make things
clear then it's a warning sign that your code may need refactoring.
--
Tony
--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)SEEN-BY: 633/267 270 5030/786 @PATH: 379/45 1 396/45 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.