I have been inspired by @Swift - Friday Pie to code up a template based solution. It's a use of templates I'd never considered before. Here it is
#include <iostream>
template <int N>
struct CCC_temp;
template <int N>
struct AAA_temp
{
struct BBB
{
};
typename CCC_temp<N>::DDD* Return()
{
return nullptr;
}
};
template <int N>
struct CCC_temp
{
struct DDD
{
};
typename AAA_temp<N>::BBB* Return()
{
return nullptr;
}
};
using AAA = AAA_temp<0>;
using CCC = CCC_temp<0>;
int main()
{
AAA a;
std::cout << a.Return() << '\n';
}
I think I prefer it to the auto
return solution. It's a bit more long-winded, but a bit more general too.
Note - use of typename
is apparently optional (my compiler doesn't object if they are removed) but I get a little confused about exactly when typename
is required and when it is not, so I left them in.