Dear All,
I have upgraded to Boost 1.47.0 and I have spent a day on the following
strange behavior that someone who knows Boost better may explain to me.
Consider the source below. If I uncomment the line:
//cout << "";
in line 39, then the program starts working, i.e., it outputs:
0x1
If I comment out line 39, then I get
0
There are no memory leaks.
This kind of stuff gives me nightmares.
Thanks for your help and sorry for the longish example.
Thanks,
-- Alex
-----------------------------------------------------------------------
#include
#include <iostream>
using namespace boost;
using namespace std;
typedef adjacency_list,
property > GraphT;
class Graph : public GraphT
{
public:
Graph();
public:
typedef graph_traits<GraphT>::vertex_descriptor VertexType;
typedef graph_traits<GraphT>::edge_descriptor EdgeType;
public:
ostream &put(ostream &) const;
void setNetLabel(const EdgeType &, void *);
void addNet(const VertexType &, const VertexType &, void *);
private:
property_map::type net_;
};
Graph::Graph()
{
net_ = get(edge_name, *this);
}
void Graph::setNetLabel(const EdgeType &edge, void *label)
{
//cout << "";
net_[edge] = label;
}
void Graph::addNet(const VertexType &branch1, const VertexType &branch2,
void *label)
{
EdgeType ei;
bool inserted;
tie(ei, inserted) = add_edge(branch1, branch2, *this);
if (inserted) {
setNetLabel(ei, label);
}
}
ostream &Graph::put(ostream &out) const
{
graph_traits<GraphT>::edge_iterator ei, ei_end;
for (tie(ei, ei_end) = edges(*this); ei != ei_end; ei++) {
out << net_[*ei] << endl;
}
return out;
}
int main(int argc, char **argv)
{
Graph graph;
Graph::VertexType v1 = add_vertex(graph);
Graph::VertexType v2 = add_vertex(graph);
graph.addNet(v1, v2, (void *)1);
graph.put(cout);
return EXIT_SUCCESS;
}
-----------------------------------------------------------------------