I'm using an implementation of a boost graph with a boost::shared_ptr<Obj>
as an edge attribute. I have two class Obj
and Obj2
such that:
class Obj{
public:
Obj(){};
virtual func(){std::cout << "Obj func " << std::endl};
};
class Obj2: public Obj{
public:
Obj2(){};
virtual func(){std::cout << "Obj2 func " << std::endl};
};
I'm adding edges in the graph using a (simplified) function such as:
void addEdge(Vertex index, Vertex index2, const boost::shared_ptr<Obj>& edgeAttribute){
out = boost::add_edge(index, index2, edgeAttribute, graph).first;
}
That I call using :
Obj2* obj = new Obj2();
boost::shared_ptr<Obj2> obj_ptr(obj);
addEdge(index, index2, obj_ptr);
However later in my code when picking up the edge attribute by doing edgeAttr = graph[edge]
and then calling the function edgeAttr->func()
, I call Obj's func and not Obj2's.
As far as I understand, it means that somewhere my Objects are being sliced. Is this short example I gave supposed to slice my object when using boost:shared_ptr and BGL, or is it some other implementation problem of my own like the initialisation?