I am compiling a .cpp called SymbolTable. I get a lot of errors, but most of them are the same error, stemming from a problem in the header that I can't solve. The errors that I get from the header is:
Error: 'map' in namespace 'std' does not name a type |
When I try to compile the .cpp, I get these errors for every function:
Error: 'SymbolTable' has not been declared
Error: 'storage' was not declared in this scope
Error: 'search' was not declared in this scope |
The map in the header is called storage (and search is an iterator I was told to make in the .cpp file). I think the reason I'm getting an error with search is because I'm getting an error with storage. Here's what I have written for SymbolTable.h (with all comments removed)...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <string>
namespace Lab5 {
class SymbolTable {
public:
SymbolTable();
public: // element operations
void declare( std::string name, int init = 0 );
void set( std::string name, int val );
int get( std::string name ) const;
public: // table queries
unsigned int size() const;
bool contains( std::string name ) const;
void dump( std::ostream &out ) const;
private: // storage
std::map<string,int> storage ;
} ;
}
|
I don't know what's wrong here and I'm not sure what to fix. Can someone tell me what's wrong with my declaration of storage?
In SymbolTable.cpp, I get an error that reads:
'SymbolTable' does not name a type |
This happens at the constructor. Every function afterwards gives the error about SymbolTable not being declared. I'm not sure why that is either, but here is the code where it begins messing up:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
#include "SymbolTable.h"
using namespace std ;
map< string, int >::iterator search ;
SymbolTable::SymbolTable ()
{
storage.clear() ;
}
/** Functions from SymbolTable.h**/
|
I asked a tutor who wasn't looking at my code about this error and was told to forward declare SymbolTable... I don't know what that means. Research lead me to this page:
http://www.learncpp.com/cpp-tutorial/17-forward-declarations/ I'm not sure if this will help me.
I'd be happy to give you more information if it's needed.