![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
C++ error C2784 occurred in structure and STL containersBasically, one statement causes 9 errors.
The followings are my codes: CPP / C++ / C Code:
Within main() functions I have: CPP / C++ / C Code:
Anyway, before posting this, I have spent 3 hours googling but to no avail. I landed in MSDN library website, which is somewhat helpful. Here's their suggestion: CPP / C++ / C Code:
I think it might be related to my problem but I could not figure out what goes wrong. I would really appreciate it if you could kindly offer suggestions/hints urgently. This project is due in 3 days and I haven't started on the main algorithm yet. :( The errors generated: Code:
|
|||
|
#2
|
|||
|
|||
Re: C++ error C2784 occurred in structure and STL containersQuote:
A map stores its elements in sorted order. To be able to insert something in a map, you have to have a predicate. This is a way to tell the map constructor how you intend to compare two key values. If the map key values are certain types of standard things (numeric data types or std::string objects, for example), you don't need to supply the predicate, since a map can use the default predicate that is already defined for any of those data types. (It uses the template class std::less<> ::operator() for the default predicate) Since your key values are intersection objects, you must define a predicate that tells how to compare two objects of that type. The data type of the optional third argument of the map constructor is a class with a boolean () operator that defines the comparison condition. See Footnote. CPP / C++ / C Code:
Regards, Dave Footnote: The comparison could be defined as a boolean function instead of using a class with a boolean functional operator. The syntax for casting this function into the correct data type to use as the third argument in the map constructor is kind of complicated-looking, but kind of fun (if you have a weird idea of fun), and is LAAEFTWSAY (Left As An Exercise For The Weird Students Among You.) Last edited by davekw7x : 26-Oct-2009 at 11:13.
|
|
#3
|
|||
|
|||
Re: C++ error C2784 occurred in structure and STL containersHey dave.. Thank you very much.. After defining the predicate, it works!
Anyway, some bugs occur when I try to insert objects into my neighborMap object. Kindly see the snippet below: CPP / C++ / C Code:
I know that map container can only have unique keys. And I am trying to insert 40 objects (15 of them are unique) (neighborMap<intersection, neighbor>) into the map, but when I display all the objects inside the nbMap object, I only get 5 entries (instead of 15). Am I missing something? Do I have to define anything else? (since map container can only have unique keys, and giving it intersection objects, it may be unable to verify if the new key is the same as the already existing keys). And it does not produce any compile time error. Some Notes: The loop does run 40 times. When I tried to cout the info manually, without storing into any object, it produced correct result. And I don't think the goto function interferes the operations. (I know goto function is bad programming practice). I also tried various map.insert functions such as map.insert(make_pair...), map.insert(pair<... , ...> (....)), and map.insert(Typedef::value_tupe (....)). Any prompt further help or suggestion would be highly appreciated. |
|
#4
|
|||
|
|||
Re: C++ error C2784 occurred in structure and STL containersQuote:
So, if you think there is a problem with the map and its insert function: Each time through the loop: show what you are inserting, then do the "insert" thing, and then display the map. Regards, Dave |
|
#5
|
|||
|
|||
Re: C++ error C2784 occurred in structure and STL containersIt's not that I used map even though I knew it was wrong, but I just realized it it was wrong and it should have 15 objects when I tried to insert it.
Anyway, I changed my implementation to multimap, and yeah it works right on the spot. Now I can go on with my shortest-path algorithm. I really appreciate your help, Dave. |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The