Consider the following design :
template <class SecondType>
struct First
{
SecondType* _ptr;
};
template <class FirstType>
struct Second
{
FirstType* _ptr;
};
where the First
type has a pointer to a Second
type and vice-versa. The problem is that I cannot declare this because they are interdependent and I should declare First<Second<First<Second...>>>
.
How to solve this problem ?
Maybe a work-around with something that looks like CRTP but even crazier:
#include <iostream>
template <class SecondType>
struct FirstBase
{
SecondType* _ptr;
};
template <class FirstType>
struct SecondBase
{
FirstType* _ptr;
};
struct FirstDerived
: public FirstBase<SecondBase<FirstDerived>>
{
};
struct SecondDerived
: public SecondBase<FirstBase<SecondDerived>>
{
};
int main()
{
FirstBase<SecondDerived> x;
SecondBase<FirstDerived> y;
return 0;
}
If someone has a more elegant way to do this, I would be happy to see it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With