Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have problem in following code:
struct node
{
    CString         Name;
    CString         Add;
    CStringArray    Str;
}

std::map<char*>link; 


Above I declare a structure & map.
Then I add the element in map as follows:

struct node NODE;
CString lv_str;
GetDlgItemText(IDC_EDIT1,lv_str);
NODE.Name = lv_str;
GetDlgItemText(IDC_EDIT2,lv_str);
NODE.Add= lv_str;
NODE.Str.SetAt(0,lv_str);
link.insert(map<char*,node>::value_type("vaibhav",NODE));


It will give error as follows:

error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct std::pair<char node="">'(or there is no acceptable conversion)


If this has any gramatical mistakes please ignore it & also if you have any other ideas to insert the item in the map please tell me.

One more thing is that if I remove str element from structure then this code works properly.
Posted
Updated 1-Sep-10 23:37pm
v2

Unfortunately CStringArray hasn't got a copy constuctor. Value types in a map have to be copy constructable so...

CStringArray not copy constructable
-> node not copy constructable
-> std::pair< char *, node > not copy constructable
-> error 2582!

One quick way around this problem is not to mess about with 1991 style collection classes and start using std::vector instead. It's a lot easier than all the manual iteration you have to do with MFC collections.

Cheers,

Ash
 
Share this answer
 
Comments
patilvaibhavrao 2-Sep-10 6:34am    
i don't get you please in provide me correction in above program
Ignoring all minor errors, this is what should work:

First of all you need to specify the keytype in the map declaration like so:
std::map<char*,node>link;

After that you may wish to insert items simply by using the [] operator:

node NODE;
//Node init here
//...
//Insert item (the map entry will be created if it was not there yet)
link["vaibhav"] = NODE;

Good luck to you and please let me know if this helps!
 
Share this answer
 
Comments
patilvaibhavrao 2-Sep-10 6:07am    
still their is an error
patilvaibhavrao 2-Sep-10 6:09am    
error C2582: 'node' : 'operator =' function is unavailable
tolw 2-Sep-10 6:30am    
Sorry - see Aescleal's answer instead - it's much better :)
patilvaibhavrao 2-Sep-10 6:34am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900