Date: Mon, 30 Dec 2024 13:43:57 +0000
Dear Experts,
Consider:
struct A {
virtual ~A() = default;
....
};
struct B: A {
....
};
class C {
struct D: B {
....
};
public:
D* d; // Or unique_ptr<D> etc.
....
};
Let's say that C is declared in C.hpp. I could forward-declare D in that header:
class C {
struct D;
public:
D* d;
};
Question: has the idea of a "partial forward declaration" ever been considered, where
D is declared as a struct that inherits from B, but with the body omitted? E.g.:
class C {
struct D: B;
public:
D* d;
};
The aim is to make it possible for a user of C to use the methods defined in A and B,
while keeping the details of D hidden.
Is this implementable? I could imagine that there could be issues with multiple inheritance.
Of course an alternative is:
class C {
struct D;
public:
B* d;
};
The disadvantage of this is that within the implementation of C, where I know that d is
actually a D*, I would constantly need to cast it.
This idea of partial forward declarations has occurred to me before with slightly
different motivations.
Thoughts anyone?
Phil.
Consider:
struct A {
virtual ~A() = default;
....
};
struct B: A {
....
};
class C {
struct D: B {
....
};
public:
D* d; // Or unique_ptr<D> etc.
....
};
Let's say that C is declared in C.hpp. I could forward-declare D in that header:
class C {
struct D;
public:
D* d;
};
Question: has the idea of a "partial forward declaration" ever been considered, where
D is declared as a struct that inherits from B, but with the body omitted? E.g.:
class C {
struct D: B;
public:
D* d;
};
The aim is to make it possible for a user of C to use the methods defined in A and B,
while keeping the details of D hidden.
Is this implementable? I could imagine that there could be issues with multiple inheritance.
Of course an alternative is:
class C {
struct D;
public:
B* d;
};
The disadvantage of this is that within the implementation of C, where I know that d is
actually a D*, I would constantly need to cast it.
This idea of partial forward declarations has occurred to me before with slightly
different motivations.
Thoughts anyone?
Phil.
Received on 2024-12-30 13:43:59