I am building a small graph library to learn C++ and graph theory. I come from a year using nothing but Java, so there are a few things I don't quite get about C++.
To represent edges of a graph, I have built four classes edge
, d_edge
, w_edge
and dw_edge
, for edges (no direction, no weight), directed edges (no weight), weighted edges (no direction) and directed weighted edges, respectively.
Instinctively, edge
will be my base class, from which the other classes will inherit. But, as I understand it, as dw_edge
is a "combination" of both d_edge
and w_edge
, it should inherit from both classes.
At the moment, I have defined some headers :
// edge.hpp
class edge {
public:
edge();
std::pair<vertex&, vertex&> get_vertices();
protected:
vertex& v1, v2;
};
// d_edge.hpp
class d_edge: public edge {
public:
vertex& get_starting_vertex();
vertex& get_ending_vertex();
void reverse();
};
// w_edge.hpp
template <class T>
class w_edge: public edge {
public:
w_edge(vertex& v1, vertex& v2, T& weight);
w_edge(edge& e, T& weight);
T& get_weight();
void set_weight(T& weight);
protected:
T& weight;
};
// dw_edge.hpp
template <class T> // ?????
class dw_edge: public d_edge, public w_edge {};
So... Yeah. Can I have an empty dw_edge
class implementation? Is it bad or rather good?
Moreover, as you can see in the code above, dw_edge
extends w_edge
which is a template class. Does dw_edge
have to be a template class, or can I just remove the statement?