J
Jimmy Johns
Hi, I have some classes as follows:
#include <iostream>
using namespace std;
class A {
public:
virtual A* clone() const = 0;
};
class B {
public:
B(const B& rhs) : p(0)
{
delete p;
p = new int;
*p = *rhs.p;
}
private:
int* p;
};
class C : public A, public B {
public:
C* clone() const
{
#24 return new C(*this);
}
};
int main()
{
#29 A* pa = new C;
A* pa2 = pa->clone();
}
this code gives the following errors under g++/cygwin:
29: no matching function for call to C::C()
24: candidates are C::C(const C&)
okay... this is puzzling. If I take out B's copy constructor, then it
compiles. It also appears that if I define any sort of new constructors
(default, non-defualt ones), then I cannot use the compiler supplied
defaults. The compiler then complains that it cannot find those default
constructors. Is this just an issue with MI or in general? Also, are there
any solutions to this besides defining all the constructors, copy
constructors in the inheritance hierarchy? Thanks in advance.
JJ.
#include <iostream>
using namespace std;
class A {
public:
virtual A* clone() const = 0;
};
class B {
public:
B(const B& rhs) : p(0)
{
delete p;
p = new int;
*p = *rhs.p;
}
private:
int* p;
};
class C : public A, public B {
public:
C* clone() const
{
#24 return new C(*this);
}
};
int main()
{
#29 A* pa = new C;
A* pa2 = pa->clone();
}
this code gives the following errors under g++/cygwin:
29: no matching function for call to C::C()
24: candidates are C::C(const C&)
okay... this is puzzling. If I take out B's copy constructor, then it
compiles. It also appears that if I define any sort of new constructors
(default, non-defualt ones), then I cannot use the compiler supplied
defaults. The compiler then complains that it cannot find those default
constructors. Is this just an issue with MI or in general? Also, are there
any solutions to this besides defining all the constructors, copy
constructors in the inheritance hierarchy? Thanks in advance.
JJ.