[antlr-interest] Re: symbol table in C++
lgcraymer
lgc at mail1.jpl.nasa.gov
Sat May 31 11:26:42 PDT 2003
If you follow the canonical C++ paradigm, non-inlined method code
should be defined in .cpp files, with class definitions, including
method prototypes, in a .h file. For your example, A::hello() might
be defined in an A.cpp file that looks like
#include "A.h" // defines class A
#include "B.h" // defines calss B
void A::hello() {
pb->hello();
}
with A.h something like
class B;
class A {
private:
B *pb;
public:
A(B *);
void hello();
};
--Loring
--- In antlr-interest at yahoogroups.com, "Fan Yang" <yhhf_dy at y...>
wrote:
> Thank you for your help.
>
> > The trick is that Java uses references--each of the cross-
> referenced
> > items is actually a pointer, but the compiler hides this--and
all
> > pointers are of fixed size which makes memory allocation easy.
To
> > do the same thing in C++, you will have to make the references
> > explicit--"HashTable& foo" for example instead of "Hashtable
foo".
>
> That's exactly what I did. I have used pointer/reference
throughout
> the new implementation.
>
> > You may also need to declare a forward reference to the class--
that
> > should just be a line of the form class Hashtable;
>
> I have used forward references in the new implementation. But the
> problem is that you can't reference members of the type which is
> defined by forward reference. For example, there are compile
errors
> if you use forward referennce for hashtable or symboltable. The
> reason is that JavaHashtable calls SymbolTable.LookupDummy(), and
> SymbolTable calls JavaHashtable.get().
>
> The following code snip simplifies the former problem.
> class B;
> class A{
> private:
> B*pb;
> public:
> A(B*b):pb(b){}
> void hello(){
> pb->hello(); // complie error
> }
> };
>
> class B{
> private:
> A*pa;
> public:
> ...
> void hello(){
> }
> }
>
> I know Template can overcome this simple problem. but the symbol
> table program is much more complex than above example. I'm not
sure
> it's a right way to do it. Does there exist some kind of patterns
to
> deal with conversion from java to c++ code. thanks.
>
> Fan
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list