Class metthod with variable number of arguments

This is part of my class-definition.
1
2
3
4
5
6
7
class BasexClient {
  public:
    BasexClient (const std::string&, const std::string&, const std::string&, const std::string&);
    virtual ~BasexClient();
    void Command(const std::string & command);
    void Create(const std::string & dbName) { return Create(dbName, "");};
    void Create(const std::string & dbName, const std::string  & content);


As you can see the 'Create' method can accept 1 or 2 arguments. And the method I used here can be easily applied in cases where there are only a few variants in the method call.

My question is what is the usual or preferred method to be able to make use of a variable number of arguments?
Do I have to use templates as is proposed in https://stackoverflow.com/questions/69737297/constructor-with-variable-number-of-arguments ?
If the number of arguments is truly variable, then a variadic templated function. If however the variation of arguments are few then I'd use overload function. Whichever comes down to ease of use/implementation.

PS. Also don't forget that function params from the right can be optional if a default is supplied.
Last edited on
Changing
void Create(const std::string & dbName, const std::string & content);
into
void Create(const std::string & dbName, const std::string & content = "");
worked.

One off these days I'll have to figure out how to create a variadic templated function.
I hope that using the recently acquired knowledge this is not too difficult.
Topic archived. No new replies allowed.