Deriving from BidirectionalGraph<> & problem with Clone()

Topics: graph
Aug 13, 2010 at 11:14 PM
Hi, I think it would be good idea to add a copy constructor to BidirectionalGraph<>. Here's how I arrived at that conclusion: I want to have a slightly customized bidirectional graph. So, naturally I make a class, MyGraph, that derives from BidirectionalGraph<>. All is well, except that statements such as the following fail: "MyGraph gg = g.Clone();", where g is of MyGraph. The issue is that Clone() is coming from the base class, and has return type of BidirectionalGraph<>. Hence the compiler asks for explicit cast. And well, just a cast doesn't really work, because there is more stuff in MyGraph that needs to be copied too. So, I try to write MyGraph.Clone(). Now the question is how to clone the base class stuff. BidirectionalGraph<> provides Clone(), but no copy constructor (there is a private constructor that is essentially a copy constructor). I don't see any way of using BidirectionalGraph<>.Clone() inside MyGraph.Clone() to clone the base class members. Is it possible? (I'm a newbie to C#, so maybe I'm missing something). Otherwise, the best solution is to add a public copy constructor to BidirectionalGraph<>. Well, I added it in my local copy of QuickGraph code. Let me know if I should pass it on as a patch. thanks, Rhishikesh