In short:
- I have a base class
A_base
without template parameters and a derived classA
that has two. - The function
foo()
only accepts base class objects foo()
is supposed to return an object which has the same type as the derived classes' first template parameter T.
The reason for this is that I don't want to specialize foo() for ALL variations of A which you can imagine could be hundreds.
To illustrate this in code:
#include <cstdlib>
struct A_base
{
};
template <typename T, size_t S>
struct A : A_base
{
using P = T; // <-- how do I get here from base class A?
T arr[S];
};
template <typename T>
auto foo(const A_base& ref) -> decltype(/* somehow get P*/)
{
return /* object of type P */;
}
int main()
{
A<int, 10> a;
foo(a);
}
I typedefd another parameter P to T because I thought this would make the class "own" the type and provide for better access. I was hoping for a solution without virtual methods, because I got around using virtual calls until now.