Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:17:30+00:00 2026-06-04T09:17:30+00:00

I am trying to implement the a map from the C++ STL as follows:

  • 0

I am trying to implement the a map from the C++ STL as follows:

#include <string>
#include <iostream>
#include <map>
using namespace std;
#include "assembler.h"

// This Class makes use of the Map Template from the Standart Template Library
// All addresses are stored as numerical (Dec) integers

SymbolTable::SymbolTable() { // Constructor
    map <string, int> symbolTable;
    int address = 0;
}

void SymbolTable::addEntry(string symbol, int address) {
symbolTable[symbol] = address;
address++;
}

// Returns true if symbolTable already contains symbol
bool SymbolTable::contains(string symbol) {
    if (symbolTable.find(symbol) == symbolTable.end()) { return true; }
    else { return false; }
}

int SymbolTable::getAddress(string symbol) {
    return symbolTable[symbol];
}

I try to compile this with

c++ *.cpp -0 assembler.out

and I get the following error message:

symboltable.cpp:57:9: error: no viable conversion from 'mapped_type' (aka 'std::basic_string<char>') to 'int'
    return symbolTable[symbol];
           ^~~~~~~~~~~~~~~~~~~
1 error generated. 

I have searched for this error online and all I get is bug reports relating to the STL and I cannot figure out if those reports are the same problem I am having and if so how to get around it. Am I doing something wrong?

I have tried (probably stupidly) to typecast the offending line as

return (int) symbolTable[symbol];

Thank you for any help.

My header file declares the class as:

class SymbolTable {
public:
    SymbolTable();
    void addEntry(string, int); 
    bool contains(string);
    int getAddress(string);
private:
    map <string, string> symbolTable;
    int address;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:17:32+00:00Added an answer on June 4, 2026 at 9:17 am

    This:

    SymbolTable::SymbolTable() { // Constructor
        map <string, int> symbolTable;
                            ^
                            ^
    

    is a function-local variable, not a member variable. It is not the same as the symbolTable that you’re accessing in e.g. getAddress, which presumably is a member variable. You haven’t shown the class body, but my guess is that it’s defined differently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement an identity map using generics. I have an abstract class,
i'm trying to use the stl map with a class that i've created, from
I am trying to implement the MyLocationOverlay class from google maps. However, when I
I am trying to implement a 7-segment counter using VHDL. The counter starts from
I'm trying to implement the code from this tutorial: This is the managed bean:
i'm trying to implemente a map view as a sliding drawer view from bottom
I am trying to implement google map api into one of my web page
I trying to implement the active record pattern using Java/JDBC and MySQL along with
What I am trying to do is to write a custom class extending Map[DateTime,
I am trying to implement Bidirectional Mapping with Fluent NHibernate Mapping. Code snippet from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.