While attempting to provide an implimentation to this question, I got stuck on an error. I’m getting errors for 8 of my functions like this:
f:\code\utilities\hypergraph\hypergraph\hypergraph.h(233): error C2244: ‘hypergraph::add_edge’ : unable to match function definition to an existing declaration
f:\code\utilities\hypergraph\hypergraph\hypergraph.h(68) : see declaration of ‘hypergraph::add_edge’
definition
‘hypergraph::node_iter hypergraph::add_edge(void)’
existing declarations
‘std::set::node*,ptr_cmp::node,P>,A>::const_iterator hypergraph::add_edge(void)’
for this class:
template<class T, class P>
struct ptr_cmp
: public std::binary_function<T, T, bool> {
P p_;
ptr_cmp(P p=P()) :p_(p) {}
bool operator()(const T* l, const T* r) const
{ return p_(*l, *r);}
};
template<class T, class P = std::less<T>, class A=std::allocator<T> >
class hypergraph {
typedef A sub_allocator;
public:
class node;
class edge;
typedef std::set<edge*, ptr_cmp<edge, std::less<edge> >, sub_allocator> edgeset;
typedef std::set<node*, ptr_cmp<node, P>, sub_allocator> nodeset;
typedef typename std::set<edge*, ptr_cmp<edge, std::less<edge> >, sub_allocator>::const_iterator edgeiter;
typedef typename std::set<node*, ptr_cmp<node, P>, sub_allocator>::const_iterator nodeiter;
class node { /*SNIP*/};
class edge { /*SNIP*/};
hypergraph(P pred=P(), A alloc=A());
nodeiter add_node(); /* beginning of 8 with the error */
nodeiter add_node(const T& rhs);
nodeiter add_node(T&& rhs);
nodeiter add_edge();
nodeiter erase(nodeiter iter);
nodeiter erase(node* iter);
nodeiter erase(edgeiter iter);
nodeiter erase(edge* iter); /* end of 8 with the error */
const nodeset& nodes() const;
const edgeset& edges() const;
A get_allocator() const;
protected:
hypergraph(const hypergraph& rhs);
hypergraph& operator=(const hypergraph& rhs);
A a_;
nodeset nodes_;
edgeset edges_;
unsigned int edgecount_;
};
And this function definition:
template<class T, class P, class A>
typename hypergraph<T,P,A>::node_iter hypergraph<T,P,A>::add_edge()
{
std::unique_ptr<edge> ptr = new edge(edgecount_++, sub_allocator(a_));
std::pair<edgeiter, bool> r = edges_.insert(ptr);
ptr.release();
return r.first;
}
I’m sure it’s a stupid thing, but I can’t figure out why MSVC10 can’t match that prototype to that function.
And I think this code has an issue with const-ness, caused by containers of pointers, but I’ll address that in a separate question.
Return value:
should be: