Help with Solving Errors

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.
Last edited on
You should include in your header the following standard header <map>
As for the second error you should specify your namespace in which the class was defined.
Last edited on
Oh! Thanks for the help with the second error. That solved it!

The lab says I can't add any headers-- everything there is all that's allowed. Including <map>, however, gives me other errors:


error: string was not declared in this scope
Note: suggested alternative: /usr/include/c++/4.6/bits/stringfwd.h
Note: 'std::string'

Last edited on
Yeah for the first errors, ie: your first post, you should have brought a '; 'after the ending block brace('}') of the class.

Hope it helps,
Aceix.
Last edited on
Without seeing the code where the error has occured I can say nothing. It seems that somewhere you forgot either to include header <string> or to use namepsace qualificator.
Thank you, Aceix. I think that was just a copy error (I'm copying from a terminal window), because I checked my code and it is in there. But, I'll fix the header here so it's more clear!
Also, the second part of your first post,
SymbolTable::SymbolTable ()

I think must have been: Lab5::SymbolTable::SymbolTable()

Hope it helps,
Aceix.
Topic archived. No new replies allowed.