The first thing that's wrong with the code is using C functions all over the place. The second thing is the map constructor's not running, because you're using C functions (specifically malloc) all over the place. Thirdly even if it did run it'd leak resources (memory) as you're not using the C functions you are using properly (where's the two calls to free?).
So... Don't use malloc. Don't use strcpy, use a string instead. There's no point using the typedef for a struct - in C++ you don't need them in half the places you do in C. Doing that lot'll make your code far simpler:
typedef std::map<std::string, int> value_map;
struct node
{
std::string name_;
value_map values_;
};
std::ostream &operator<<( std::ostream &str, const value_map::value_type &v )
{
return str << v.second;
}
int main()
{
std::tr1::shared_ptr<node> n( new node );
n->name_ = "prasad";
n->values_[ "A" ] = 1;
n->values_[ "B" ] = 2;
for( value_map::const_iterator iter = n->values_.begin();
iter != n->values_.end(); ++iter )
{
std::cout << *iter << std::endl;
}
}
It could just be me but note how much easier main is to follow... And it won't run any slower.
I'm also a bit worried about anyone that calls a class node, this seems to imply that they're about to go forth and spew out a tree or list class of their own. Don't do it unless std::list and std::map don't work for your requirements!
Good luck,
Ash