For example how to impalement Wrapper::call_to_func
that argument list call_to_func should be as func
class A
{
void func(int, char, double);
};
template<class T>
class Wrapper
{
public:
void call_to_func(....)
{
m_t.func(....)
}
T m_t;
}
>Solution :
You can make call_to_func a variadic method template with a template parameter pack , and use std::forward to perfectly forward the arguments to func:
#include <iostream>
#include <utility>
class A {
public:
void func(int i, char c, double d) {
std::cout << "func" << " " << i << " " << c << " " << d << "\n";
}
};
template<class T>
class Wrapper {
public:
template <typename ... Ts>
void call_to_func(Ts&& ... args) {
m_t.func(std::forward<Ts>(args)...);
}
T m_t;
};
int main() {
Wrapper<A> w;
w.call_to_func(1, 'a', 2.3);
}
Output:
func 1 a 2.3