Answer the question
In order to leave comments, you need to log in
How to make a function accept an unlimited number of arguments of different types?
How to make a function accept an unlimited number of arguments of different types?
Answer the question
In order to leave comments, you need to log in
In C++, it is much more difficult to write a function that takes a variable number of arguments of the same type than it is to write different types.
The problem is solved with the help of the so-called. variable template parameters [ ? ].
template< typename... TArguments >
void Foo( const TArguments&... arguments )
{
static_assert( sizeof...( TArguments ) > 0, "This function shall not be called without arguments." );
}
Unlimited number of arguments - you can simply take a pointer to the beginning of the list as a single argument, for example. And the list can be of any length.
In order for a function to work with different inputs, use templates (function templates): Wikipedia
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question