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

  • SEARCH
  • Home
  • 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 6327933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:22:06+00:00 2026-05-24T17:22:06+00:00

I have been having this problem for awhile with my code, looking for my

  • 0

I have been having this problem for awhile with my code, looking for my mistake I can’t see it. I have a map, map I am mapping keywords to the values.
My problem is sometimes when inserting keyword = “Blue” the value is inserting into the Key for “Red”.
So instead of,
Key: Red, Value: obj1, obj2
Key: Blue, Value: obj3, obj4
I get,
Key: Red, Value: obj1, obj2, obj4 (obj4 should be keyed to Blue)
Key: Blue, Value: obj3

Not sure what it can be since the same version of the code works for other maps that I have, they just don’t have as many Keys.

addKeywordsForObject(const Object* const object, int nKeywords, ...)
{
va_list     keywords;
char        *keyword;

va_start(keywords, nKeywords);
for (int i = 0; i < nKeywords; i++) {
    keyword = va_arg(keywords, char*);

    if(objectToKeywordMap.find(keyword) == objectToKeywordMap.end()) {  
        keywordObject = new ObjectSet();
        keywordObject->insert(const_cast<Object* const>(object));
        objectToKeywordMap.emplace(StringToObjectSetMap::value_type(keyword,keywordObject));
    }
    else {
        keywordObject->insert(const_cast<Object* const>(object));   
        objectToKeywordMap.emplace(StringToObjectSetMap::value_type(keyword,keywordObject));
    }
}
va_end(keywords);
}  
  • 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-24T17:22:06+00:00Added an answer on May 24, 2026 at 5:22 pm

    I see no declaration for keywordObject, so I shall assume it’s a global. The case of adding a new object to a keyword which is already present is dealt with in the else. What is the value of keywordObject in this case? Who sets it?

    There are a number of other problems with this code, some mentioned in other answers and comments.

    • missing return type for addKeywordsForObject
    • possible usage of char* as a map key which requires special handling (not clear, because you haven’t shown the declaration of StringToObjectSetMap)
    • a function which takes a variable number of parameters by using ellipsis (almost never a good idea in C++)
    • use of a global variable where a local variable is appropriate
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having this problem for awhile now. Anyways, given this code: <table> <tr>
I have been trying to tackle this problem , but I am having difficulty
This is a really weird problem that I have been having. When I download
I have been having problems with toBase64() for awhile. I am hoping someone can
I have been having this problem wherein my threads stop execution and go into
I have been having this issue in iterating through an array of keys and
We have been having some debate this week at my company as to how
Hello I have been having trouble with this for a while now. I have
I have been struggling with this for quite some time having been accustomed to
No doubt elements of this question have been asked before, but I'm having trouble

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.