Given example DirectedGraph
:
What is the definition of the two nested class' constructors? Based on my observation below, I am guessing it has to do with the constructor's parameters being a sibling class.
DirectedGraph.tpp
template < class Key,
class Compare = std::less<Key>,
class Allocator = std::allocator<Key> >
class DirectedGraph
{
public:
// only used for returns/queries
class Edge
{
public:
Edge(Vertex&,
Vertex&);
private:
Vertex& from;
Vertex& to;
};
class Vertex
{
public:
Vertex(Key&);
~Vertex(void);
private:
value T&;
std::set<Vertex *> edges;
};
DirectedGraph(void);
~DirectedGraph(void);
<...lots of methods...>
private:
size_t num_edges;
std::set<DirectedGraph<Key, Compare, Allocator>::Vertex *> vertices;
};
Visual Studio give me an error (E0147
declaration is incompatible with "DirectedGraph<Key, Compare, Allocator>::Edge::Edge(<error-type> &, <error-type> &)
" )
DirectedGraph.cpp
template <class Key, class Compare, class Allocator>
DirectedGraph<Key, Compare, Allocator>::Edge::Edge
(
Vertex& from,
Vertex& to
)
{
}
but curiously, not with the Vertex constructor:
template<class Key, class Compare, class Allocator>
DirectedGraph<Key, Compare, Allocator>::Vertex::Vertex
(
Key& value
)
{
}
I am guessing this has to do with the latter not requiring its sibling nested class as a constructor parameter?
Thanks in advance, I am completely stumped.
Edit #1
Forward declaring (or changing position) as per quimby's comment or user7860670's comment did the trick for the errors. With a few more tweaks, went from 168 errors to 1.
DirectedGraph.tpp
template < class Key,
class Compare = std::less<Key>,
class Allocator = std::allocator<Key> >
class DirectedGraph
{
public:
// only used for returns/queries
class Edge;
class Vertex;
class Edge
{
... everything else identical to above
}
DirectedGraph.cpp
template<class Key, class Compare, class Allocator>
DirectedGraph<Key, Compare, Allocator>::Vertex::Vertex
(
Key& value
)
{
}
template <class Key, class Compare, class Allocator>
DirectedGraph<Key, Compare, Allocator>::Edge::Edge
(
Vertex& from,
Vertex& to
)
{
}