How to have input parameters like std::vector

What I am aiming to do is to have parameters for a function be similar to std::vector where you choose the parameters and there is a minimum of 1 parameter. Thanks!
This explains how to do a function like the C functions (printf, etc) that have random numbers of arguments. Is this what you are asking?
https://en.cppreference.com/w/cpp/language/variadic_arguments

There are a number of other answers to a number of other similar questions ... can you elaborate if that was not the right guess?
There's also the C++ way of doing this using variadic templates (parameter pack)
https://en.cppreference.com/w/cpp/language/parameter_pack

Then there is an initializer-list
https://en.cppreference.com/w/cpp/utility/initializer_list

If the parameters vary by type, then there's function overloading - with the right params being optional.

Maybe a bit of defining terminology is in order.

A std::vector is not a function, it is a template class with member functions (methods). More than a few overloaded methods.

Your question needs more explanation so we can better narrow down what you are trying to do.
George P wrote:
A std::vector is not a function, it is a template class with member functions (methods).

To be pedantic, it's a class template.

It's not a class, it's a template for generating classes.

std::vector<int> would be a class though.
Point well made, Peter87.

Weird, I typed class template originally, but it didn't look quite right so I swapped it.

My petard hoisted quite nicely. :D

Last edited on
Topic archived. No new replies allowed.