I just don't get it, what's with this->?


I'm looking at some code to help me understand how to use the dbghelp.dll Windows stack walking and symbol discovery stuff and the code I've found on the net uses a programming style that I've seen a few times before and have never understood the reason for.

if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, 
      &(csEntry.offsetFromSmybol), pSym) != FALSE)
   strcpy_s(csEntry.name, pSym->Name);
   // UnDecorateSymbolName()
   this->m_sw->pUDSN( pSym->Name, 
      csEntry.undName, STACKWALK_MAX_NAMELEN, 
   this->m_sw->pUDSN( pSym->Name, csEntry.undFullName,
   this->OnDbgHelpErr("SymGetSymFromAddr64", GetLastError(), s.AddrPC.Offset);
Why did the author feel it necessary to be explicit about his use of the current object by specifying this-> when accessing members? Where did this style come from and what purpose is it supposed to serve?


Many people advocate it as an alternative to Hungarian. Especially in the presence of auto-completion, this-> gives more focused help than just Ctrl+Space.

Personally, I hate it :-)

- Kim

i suppose it's just a way of removing potential ambiguities, just as the global namespace prefix :: is used sometimes to make ensure the correct function lookup is found. i see that quite a lot, especially for ::SysAllocString for some reason. the only time i've actually seen a need for that is with a socket class that uses ::connect etc. when the class has its own connect function.

i don't normally use either myself, but sometimes if i'm lazy i will type this-> to see what the autocomplete brings up. i would always delete it once i've found what i'm looking for though.

i could kind of understand the reasoning for using it instead of hungarian but i wouldn't recommend it - and the example given doesn't do away with the pesky m_ anyway!

great site btw, fast becoming one of my favourites :)


I often use the global namespace prefix as "insurance against future change"... But to be honest it's just a habit I picked up a long time ago and with my current style of testing it's probably becoming unnecessary; in fact I can't remember when it's actually 'saved' me...

The this-> stuff just looks messy to me, especially with default syntax highlighting... I'd personally prefer a 'wart' on the variable (leading m_, trailing _ I don't really care as long as it's consistent).

Sometimes "this->" is even necessary. With dependent
names and 2-phase lookup:


Vagn Johansen

Interesting link, thanks.

In that situation I usually take one of the other routes; base@lt;T@gt;::base_func() etc...

Just like to know whether you use external libraries specially 'BOOST' in your commercial projects and related pros-n-cons ?

Also i like to know your initial strategy of Software development. I mean you've written a lot about your coding and tsting techniques but i like to know how you start the project, whether you believe in UML and how you carry out analysis. If you've time then please write something about it here in the blog. Or if you've ever written anything abt it before then please give me the link ?

Ahsan, thanks for the questions. I've answered them in a new post here.

Leave a comment