Hi, Professor,Here are the relevant comments from SymTab.h:
Is this the right way to dump a symbol table?
void Semant::analyzeProg(){
ast->addDeclr(classSymTab);
classSymTab->dump(cout);
}
When I compile the above code, I got the following error:
g++ -g -Wall -Wno-unused -c -o semant.o semant.cc
SymTab.i: In method `void SymTab<Class>::dumpHelper(ostream &) const':
SymTab.i:74: instantiated from `SymTab<Class>::dump(ostream &) const'
semant.cc:95: instantiated from here
SymTab.i:55: no match for `ostream & << Class &'
/usr/usc/gnu/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/../../../../include/g++-3/iostream.h:77: candidates are: class ostream & ostream::operator <<(char)
/usr/usc/gnu/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/../../../../include/g++-3/iostream.h:78: class ostream & ostream::operator <<(unsigned char)
[... lots more deleted...]
gmake: *** [semant.o] Error 1
To call dump, << needs to be defined for the value type you use. You can define one here that just prints out a little info about the Class so you make sure you have put in the correct entries. OR for the classSymTab, you can just call dumpKeys (another SymTab func) that just prints the keys and not the values.
If you don't know the syntax for overloading <<, there is an example of the header and the func def for one in StringTab.h and StringTab.cc, respectively. That function is for type Symbol, and that's why we don't get the compile error when we do the dump's in testSymTab.cc.