Skip to content

Commit

Permalink
Add dynamic_cast in raw pointer overload of addEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldu committed Oct 3, 2023
1 parent 0c85ec0 commit 754fddf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/CXXGraph/Graph/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,8 @@ template <typename T>
void Graph<T>::addEdge(const Edge<T> *edge) {
if (edge->isDirected().has_value() && edge->isDirected().value()) {
if (edge->isWeighted().has_value() && edge->isWeighted().value()) {
auto edge_shared = make_shared<DirectedWeightedEdge<T>>(*edge);
auto edge_shared = make_shared<DirectedWeightedEdge<T>>(
*dynamic_cast<const DirectedWeightedEdge<T> *>(edge));
this->edgeSet.insert(edge_shared);

std::pair<shared<const Node<T>>, shared<const Edge<T>>> elem = {
Expand All @@ -879,7 +880,8 @@ void Graph<T>::addEdge(const Edge<T> *edge) {
}
} else {
if (edge->isWeighted().has_value() && edge->isWeighted().value()) {
auto edge_shared = make_shared<UndirectedWeightedEdge<T>>(*edge);
auto edge_shared = make_shared<UndirectedWeightedEdge<T>>(
*dynamic_cast<const UndirectedWeightedEdge<T> *>(edge));
this->edgeSet.insert(edge_shared);

std::pair<shared<const Node<T>>, shared<const Edge<T>>> elem = {
Expand Down

0 comments on commit 754fddf

Please sign in to comment.