I am having a problem calling a template function with two template arguments.
I have a class and the class accepts objects of two different types. I don't know the types yet, so I left them as template parameters. I then store the objects in wrapper classes. In the end I want to be able to call a templated function with two template arguments, that takes my two objects. But I am perplexed at how to do this.
Here is a stripped down version of the code to explain my problem.
template<typename A, typename B>
void someTemplateFunction(A a, B b);
class Problem
{
private:
class WrapperA
{
public:
virtual void doSomething() = 0;
};
template<typename A>
class ConcreteWrapperA : public wrapperA
{
private:
A a;
public:
ConcreteWrapperB(A b_) : a(a_) {}
virtual void doSomething();
};
class WrapperB
{
public:
virtual void doSomething() = 0;
};
template<typename B>
class ConcreteWrapperB : public wrapperB
{
private:
B b;
public:
ConcreteWrapperB(B b_) : b(b_) {}
virtual void doSomething();
};
WrapperA *a;
WrapperB *b;
public:
template<typename A>
void setA(A a)
{
a = new ConcreteWrapperA<A>(a);
}
template<typename B>
void setB(B b)
{
a = new ConcreteWrapperB<B>(b);
}
void call_someTemplateFunction(); // ??????? How do i do this?
};
AorBtypes known? I mean, e.g., that you know thatBcan beint, long or shortand nothing more. If yes, then I can provide an answer. On the other hand if you can set both with one function, then of course use 1st answer.AandBare not know. I though about usingboost::varianttogether with visitors. But that doesn't seem to work.Problem::setAorProblem::setB?AandBare not known. I am developing a library and I don't know in advance what concrete types the user will pass asAandB.