Consider the following program
class Node {
public:
virtual void Visit() = 0;
};
class Graph {
public:
virtual void Visit();
};
class GraphNode1 : public Node, Graph {
};
class GraphNode2 : public Node, Graph {
using Graph::Visit;
};
class GraphNode3 : public Node, Graph {
public:
virtual void Visit() {
Graph::Visit();
}
};
int main()
{
GraphNode1 a;
GraphNode2 b;
GraphNode3 c;
}
It does not compile, but complains that GraphNode1 and GraphNode2 are abstract, since Node::Visit is pure virtual.
I would have assumed that both GraphNode1 and GraphNode2 were fine, since:
- They contain an implementation of
Visit. - They contain only a single implementation of
Visit, so there should be no ambiguity.
Can anyone explain why I have to create an explicit implementation to make it work.