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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:08:34+00:00 2026-05-23T06:08:34+00:00

I’ve a incertitude about std::map on c++: I did a Object C_Configuration that loads

  • 0

I’ve a incertitude about std::map on c++:

I did a Object C_Configuration that loads a linked library (.so) C_ConfigurationLibrary.

The C_Configuration class has a std::map and The C_ConfigurationLibrary has a method that initializes the std::map.

If I access to the std::map from C_Configuration with a “for” loop:

std::map<const char*, const char*>::iterator l_item;
for(l_item = m_configuration_map.begin();
    l_item != m_configuration.end();
    l_item++)

This is OK;

But if I use :

m_configuration[VALUE_KEY] // the value is NULL

This is not OK;

My CODE:

C_Configuration::C_Configuration()
{
    m_configuration = LoadLibrary(); // load the linked library (.so)

    if(m_configuration != NULL)
    {
        // DEBUG
        LOG_DEBUG("Loading Key from plugin...");

        m_configuration->LoadKeys(m_configuration_map);

        std::map <const char*, const char*>::iterator l_item;
        for ( l_item = l_configuration_map.begin();
              l_item != l_configuration_map.end();
              l_item++ )
        {                
            //THIS IS OK             
        }

        m_configuration_map[FIRST_KEY] // THIS IS NOT OK
    }
}

void C_ConfigLibrary::LoadKeys(std::map<const char*, const char*>& p_configuration_map)
{
    // DEBUG
    LOG_DEBUG("Loading Keys...");

    p_configuration_map.insert ( std::make_pair<const char*, const char*>(FIRST_KEY, FIRST_VALUE) );
    // DEBUG
    LOG_DEBUG("Loaded Key DBUS used: %s",m_dbus_used.c_str());
    p_configuration_map.insert ( std::make_pair<const char*, const char*>(SECOND_KEY,SECOND_VALUE) );
}

Can you help me?

thanks so much

  • 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-23T06:08:35+00:00Added an answer on May 23, 2026 at 6:08 am

    You’re using const char*s as keys, but pointers are compared on their memory addresses and not the text to which they point. Consequently, when you have a string literal in the shared library, and the same text in a string literal in the main app object, they can have different addresses and will not compare equal as keys.

    You’re much better off using std::strings as the keys, although it’s safe to use const char* as the values.

    FWIW, if you use const char* as a key, not only are string literals from different translation units sometimes finicky like this, but you’ll have difficultly using text from local buffers, even std::string‘s .c_str() return values – it’s just a very bad idea.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.