You cannot redirect va_args. You can redirect only va_list.
void vB(int first, va_list ap) { // do stuff with ap. } void B(int first, ...) { va_list ap; va_start(ap, first); vB(first, ap); va_end(ap); } void A(int something_else, int first, ...) { va_list ap; va_start(ap, first); vB(first, ap); // <-- call vB instead of B. va_end(ap); }
(This also means that there are functions like vprintf
.)
If you are using C ++ 11, you can do this with variable templates with perfect forwarding:
template <typename... T> void A(T&&... args) { B(std::forward<T>(args)...); }
source share