   Visual C++ problem?
  Hi all,This is my first post here, so I hope I'm doing it right!I've found what seems like a bug in VC++.  The same code seems to work fine when compiling with g++ in Linux, however I get a corruption problem in VC++ (2005 with the latest service pack).Here is the code:#include <stdio.h>#include <string>class Abstract{public:virtual ~Abstract() {}virtual Abstract* clone() = 0;};class A : public virtual Abstract{public:A() {}virtual ~A() {}};class B : public A{public:B(){vA = 5;vB = "hello";vC = 10;}virtual ~B() {}virtual B* clone() = 0;int vA;std::string vB;int vC;};class C : public B{public:C() {}virtual ~C() {}C* clone(){printf("[%s]\r\n", vB.c_str());return new C();}};int main(){B* obj = new C();obj->clone();getchar();}In the "clone" function implemented in class "C", the vB variable has become corrupt; it no longer just contains "hello".  However, if I comment out the "clone" member from the Abstract class, it works fine (even if I keep it in the "A" and/or "B" base class).  It seems to be to do with covariant return types, because if I make the return type void, the problem disappears.Any ideas anyone?All I'm trying to do is provide a clone facility at any point in the hierarchy.  I know I could use dynamic cast, but I don't understand why this wouldn't work.Thanks very much in advance!Mark.--   
  Hmm. Whatever the issue is I bet it has to do with having multiple different return types for the 'same' virtual function. Try returning an Abstract pointer instead and remove the virtual B * clone line. That is try this://virtual B* clone() = 0;and make the C clone function into:Abstract * clone() {  printf("[%s]\r\n", vB.c_str());  return new C();}edit: blah, I forgot that covariant return types are legal so I can't see what is actually wrong with your code or whether it is a visual c++ issue. Sorry.   ;  Anyway, I tried to step through the code in my debugger and the problem seems to occur in class B, whatever the problem may be. I also found that commenting out B * clone() = 0; alone fixed the issue. Perhaps Visual C++ chokes on having multiple pure virtual clone functions in the hierarchy when you only needed the one in the base class.   ;  This looks like a known bug in MSVC 2005.   