strange copy constructor behavior in inherit tree
i have three class types: Base->Center->Child, and i want to make it
posible to construct child type from parent type, so i declared them like
this:
class Base {
public:
Base(void) {}
virtual ~Base(void) {}
Base(const Base &ref) {}
};
class Center : public virtual Base {
public:
Center(void) : Base() {}
Center(const Base &ref) : Base(ref) {}
};
class Child : public virtual Center {
public:
Child(void) : Center() {}
Child(const Base &ref) : Center(ref) {}
};
it's OK to call it like this: (calling Center and Base's copy constructor)
Base base;
Center center(base);
however, these code act unexpectedly:
Child child(base);
it would call those method step by step:
1. Child(const Base &)
2. Base()
3. Center(const Base &)
No comments:
Post a Comment