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 927711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:53:47+00:00 2026-05-15T19:53:47+00:00

I have been trying to make a StringTable class that holds a simple unordered_map<string,

  • 0

I have been trying to make a StringTable class that holds a simple unordered_map<string, string>, and has the array index operator ‘[]’ overloaded to work for accessing the map; however, the compiler will tell me that I have yet to define the overloaded operator when I try to use it. My code is as follows:

CStringTable.h

#include <string>
#include <fstream>
#include <tr1/unordered_map>

class CStringTable {
public:
    bool Load(const char* filename);

    inline const char* operator [](const char* key);

    const char* Get(const char* key);

private:
    std::tr1::unordered_map<std::string, std::string>* m_StringMap;
};

CStringTable.cpp

#include "CStringTable.h"

inline const char* CStringTable::operator [](const char* key) {
    std::string sKey = key;

    return (*m_StringMap)[sKey].c_str();
}

I try to access the map as follows:

(*m_cStringTable)[msgKey]

where m_cStringTable is a pointer to an instance of the CStringTable class and msgKey is a const char*.

Can anybody enlighten me as to why this won’t work?

  • 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-05-15T19:53:47+00:00Added an answer on May 15, 2026 at 7:53 pm

    Regarding the inline keyword, the compiler needs to be able to see the body of that method as well in the .h file. So either move the implementation of the operator from the .cpp file to the .h file, or include the body of the operator in the class declaration.

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

Sidebar

Related Questions

I have been trying to make wall post from multiple pages but when i
I've been trying to make a for loop that will iterate based off of
I have been trying to find ways to make the following piece of code
I have been trying to use difference units (%, em, pt) to make a
I have been trying to figure out what I figure is a pretty simple
I am trying to make a Content Slider for my site. I have multiple
I have been trying to apply a style to my TabWidget. I've tried several
I have been trying to replace everything in xcode with stuff I can get
I have been trying to find a free (preferably open sourced) component or library
I am in the sitaution where I need to use an external session state

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.