I'm trying to implement the double dispatch pattern but I get a circular dependency that I can't resolve with forward declaration (as it was resolved in this problem link).
Below is an example of my problem:
header 1:
class Object
{
virtual void dispatchAdd(Collection& c) const = 0;
};
class Blockage: Object
{
virtual void dispatchAdd(Collection& c) const
{
c.add(*this);
}
};
class Boundary: Object
{
virtual void dispatchAdd(Collection& c) const
{
c.add(*this);
}
};
header 2:
class Collection
{
public:
void add(const Blockage& b)
{ ... }
void add(const Boundary& b)
{ ... }
...
private:
boost::unordered_set<Boundary> m_boundaries;
boost::unordered_set<Blockage> m_blockages;
}
I can't forward declare Boundary
and Blockage
in header 2, because I need a complete type to use boost::unordered_set
. Any advice to resolve this problem?