Class pseudo definition:
Base Virtual Class A:
class A {
public:
virtual ~A();
virtual void doSomething() const = 0;
};
Class B Inheriting from A:
class B : public A {
public:
void doSomething() {} const;
}
Base Virtual Class C:
class C {
public:
virtual ~C();
virtual void doSomething() const = 0;
};
Class D inheriting from C:
class D : public C {
public:
D(const &A _a = *A_Ptr(new B)) : a(_a) {}
void doSomething() {} const;
private:
const &A a;
}
A_Ptr is typedef of shared pointer of class A.
My problem is with declaring another class.
Lets call it class X:
class X {
public:
X(const &A _a = *A_Ptr(new B), const &C _c = *C_Ptr(new D(a)) : a(_a), c(_c) {}
private:
const &A a;
const &C c;
}
X(const &A _a = *A_Ptr(new B), const &C _c = *C_Ptr(new D(a))
-this part of initialization doesn't work. What does work is
X(const &A _a = *A_Ptr(new B), const &C _c = *C_Ptr(new D)
But if I do it this way, I create two shared pointers of type class A which isn't something I would want. On the other side anything like X(const &A _a = *A_Ptr(new B), const &C _c = *C_Ptr(new D(a))
or X(const &A _a = *A_Ptr(new B), const &C _c = *C_Ptr(new D(_a))
doesn't work. Is there any known way to solve this problem?
Thanks in advance : )