[antlr-interest] ASTRefCount.hpp

Ric Klaren klaren at cs.utwente.nl
Tue Jul 29 05:27:28 PDT 2003

On Tue, Jul 29, 2003 at 12:15:57PM +0100, wiggjd at sbu.ac.uk wrote:
> I have come across the following coding in ASTRefCount.hpp and
> I cannot make sense of the first line. It was included in
> support.cpp. It must have compiled but to parse it properly I 
> need to understand it. Please could the author (or anyone
> else) help?

Not sure in what exact context you encountered it. But I think you missed
the template definition in front of the class:

template<class T> class ASTRefCount {

> operator T* () const
> 	{ return ref ? static_cast<T*>(ref->ptr) : 0; }

-> Userdefined conversion from ASTRefCount<T> to T* (T is generally AST)

> T* operator->() const
> 	{ return ref ? static_cast<T*>(ref->ptr) : 0; }

Make it behave like a pointer.

> T* get() const
> 	{ return ref ? static_cast<T*>(ref->ptr) : 0; }

So the first 2 make the RefCounter behave like a pointer (to the underlying
T (AST) object) the get method can be used to get lowlevel access to the
object underlying the refcount.

If you happen to have access to the book More Effective C++ from Scott
Meyers Items 28 and 29 give quite a detailed description of this stuff.


    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
  "I think we better split up."
  "Good idea. We can do more damage that way."
  --- Ghostbusters


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list