Hi,

I'm a novice at writing C++ code, most of my experience is in C# and Java. I have tried a bunch of things but I can't seem to figure out the correct way to structure my statements. Rather than try and explain everything I'm doing wrong I will post example problem code.

std::map<ObjectA, Objectb> dict;

int test(ObjectA arg)
{
    if(dict[arg] == NULL)
    {
        dict[arg] = new ObjectB;
        initObjectBs(dict[arg]);
    }
}

This doesn't compile, obviously. I know that I need reference and pointer operators in there, I just am unsure where as this is a map object I'm using and I'm also not sure how to check for null entries correctly.

Thanks for any help.

Try map::find(). You should be able to get an analyzable result from that. Then, if you get a response that means "not found", you can call map::insert() to add the key you were checking for.

The std::map container stores instances of the pair<> data structure (a templatized struct). You may want to read up on that as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.