Public Group

set operator= not work

This topic is 4254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

set<char*,compare> t; t = set<char*,compare>();// it not work; set<char*,compare> t = set<char*,compare>();//work. why 1st fail?

Share on other sites
Works on my machine just fine. Compiles correctly, and functions as one would expect it should, but that is without 'compare' specified. Your problem likely exists in a lack of a proper operator= function contained within 'compare'.

set<char*,compare> t1;t1 = set<char*,compare>();// <- this line calls the operator= for set, //which in turn calls operator= for both char* and compare.set<char*,compare> t2=set<char*,compare>();//compiles into //set<char*,compare> t2(set<char*,compare>()); //which calls only copy constructors, and no operator=!!!

For the sake of experimentation, try deleting 'compare' from both of your examples, and compile it again.

Of course, since no error message was provided, this is really just an educated guess based on my knowledge of the language, and the real problem could be any number of things that are wrong with the code outside of what is posted here, since 'compare' isn't specified in the posted code.

Oh, and whats with the 10,000 stl topics :P

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×