I'm stuck with using a set with a few indicator reps. My code is as follows:
void Graph :: addNodes (nodeset and nodes) {for (NodeSet :: iterator pos = nodes.begin (); pos! = Nodes.end (); ++ pause) {addNode (* pos); }}
Nodeset is defined here:
typedef std :: set & lt; Node_ptr, node_ptr_Sorting_Predicate & gt; Nodeset;
The above piece of code works perfectly on my windows machine, but when I run the same part of the code on the Mac, I get the following error:
FYI, Node_PTR type: typedef boost :: shared_ptr
Can anyone tell me why this is happening?
OK, with your additional information, the problem is that addNode
Refers to a Node_ptr
per non- const
, whereas the compiler is the function to call a const boost :: shared_ptr & lt; Node & gt; & Amp;
(Note on const
). Explain to me:
std :: set
is a cooperative container that stores its elements in a sequence, using the main element to define the associative container order. If you have permission to change the key without the container, then you will cancel the container's internal order. This is the reason why I believe a std :: set & lt; T & gt; :: iterator
does not return a modifier. (Which means that you can not return the reference. For example, if you have a pos
a std :: set
should not be compiled.)
The catch with this is that only the modifiable properties will be linked to a non- const
context but what if * Pos
returns are not a convertible and will not be in this way (hence, in my example, int & r = * pos;
will not be compiled.) The reason for this is if This allowed Is, if you messed up the internal order of the non behind the sorting key back of the container can be changed through Const
context and container.
So your * pos
results for node_peter & amp;
. And that's why the compiler can not call your function
Does your addNode ()
member function actually replace this node? If not, then call it const node_ptr & amp;
should be taken.
If this happens, then you have a design problem. You can not make changes in an element that is in a set. The only thing you can do is remove it from the set, change it and add it back.
Note one side: VC9 actually collects the following code snippet:
#include & lt; Iostream & gt; # Include & lt; Set & gt; #include & lt; Typeinfo & gt; #include & lt; Iterator & gt; Int main () {std :: set & lt; Int & gt; Set; Set.insert (5); Std :: cout & lt; & Lt; * Set.begin () & lt; & Lt; '\ N'; * Set.begin () = 3; // That's an error! Std :: cout & lt; & Lt; * Set.begin () & lt; & Lt; '\ N'; Return (0); }
I believe this is an error in VC9. Dismissed it
Here's the way to solve the puzzle with a compiler that you think should not call a function, it must be burdened or wrong function with the set of offload Should call.
The function you thought should call it graph :: addNode (Node_ptr & amp;)
. The code that you thought should call it
addNode (* pos);
Change the code so that it returns the required precise parameters:
Node_ptr & amp; Tmp = * pos; AddNode (tmp);
Now the call should be compiled correctly (or by calling the correct overload), and the compiler should be sorted, if it believes that * pos
Can not be assigned to the Node_ptr & amp;
.
Typically this strategy helps me know what is wrong in such situations.
Comments
Post a Comment