mercredi 5 juillet 2023

How can I pass by reference considering inheritance?

Here's my scenario (notice the code I can edit, the code I cannot):

#include <iostream>

// the follow is untouchable (from sdk)
struct Base { };

template <class TParamQuantity = Base>
TParamQuantity* configParam(int paramId) { }

// the follow is my code (can edit as I want)
struct BaseParamScaler { };
struct LogParamScaler : BaseParamScaler { };

template <BaseParamScaler &T>
struct QRange : Base { };

LogParamScaler gLogParamScaler;

int main()
{
    configParam<QRange<gLogParamScaler>>(0);
}

What I'd like to know is being able to pass BaseParamScaler (and its childs) to configParam template method (which come from sdk).

Is there any way of doing this in C++11? Or how would you do this in some fancy way?

Note: if pass by point/value/whatever is permitted, I can do that way. But I believe stay with template is mandatory, having configParam working with them.

Aucun commentaire:

Enregistrer un commentaire