J
jgscott
I've been trawling around for an answer to this question and thought
I'd try here. I have a class Graph, which has a std::list<Node> as a
class member. Node it itself a class that makes extensive use of
pointers to represent various forms of data in the nodes of graphs,
along with pointers to neighboring nodes. This necessitates a deep
copy that iterators over the list. My copy constructor looks like:
DecomposableGraph:ecomposableGraph(const DecomposableGraph& G)
{
// Some stuff
// And now the iterator declaration:
std::list<Node, const Node&, const Node*>::iterator jt_i, jt_l, jt_m;
// use these iterators to do deep copy of G
}
The GNU compiler on my G4 Mac laptop does not object to this
declaration, which I cobbled together by trial and error message. The
code compiles, and the copy constructor works exactly as intended.
The GNU compiler on a Linux machine that I want to port this code to,
however, objects, claiming I can only have 1 member of the list
template declaration rather than 3. This leads me to believe I've
stumbled upon a peculiarity of the Mac implementation of the STL which
makes my declaration interpretable, albeit nonstandard. The problem,
as I understand it, is that I can't use a normal list<Node>::iterator
to iterator over class members of the const G the way I could over a
normal non-const function argument. But I don't know how to modify
the declaration in general to make such iteration possible.
Can anyone clue me in to the "standard" way to solve this problem, or
correct my understanding? Thanks for your time.
I'd try here. I have a class Graph, which has a std::list<Node> as a
class member. Node it itself a class that makes extensive use of
pointers to represent various forms of data in the nodes of graphs,
along with pointers to neighboring nodes. This necessitates a deep
copy that iterators over the list. My copy constructor looks like:
DecomposableGraph:ecomposableGraph(const DecomposableGraph& G)
{
// Some stuff
// And now the iterator declaration:
std::list<Node, const Node&, const Node*>::iterator jt_i, jt_l, jt_m;
// use these iterators to do deep copy of G
}
The GNU compiler on my G4 Mac laptop does not object to this
declaration, which I cobbled together by trial and error message. The
code compiles, and the copy constructor works exactly as intended.
The GNU compiler on a Linux machine that I want to port this code to,
however, objects, claiming I can only have 1 member of the list
template declaration rather than 3. This leads me to believe I've
stumbled upon a peculiarity of the Mac implementation of the STL which
makes my declaration interpretable, albeit nonstandard. The problem,
as I understand it, is that I can't use a normal list<Node>::iterator
to iterator over class members of the const G the way I could over a
normal non-const function argument. But I don't know how to modify
the declaration in general to make such iteration possible.
Can anyone clue me in to the "standard" way to solve this problem, or
correct my understanding? Thanks for your time.