Multiple Arguments with Default Argument

cout << "Hi everyone!" << endl; // :)

I want to use multiple arguments with default arguments together in a same function, can i do this? because both needs to be rightmost rigth? Can someone help please ?

Example:

1
2
enum logflag { INFO = 1, ERROR = 2, WARNING = 3, MISC = 4 };
static void logthis(logflag l = INFO, char * msg, ...);


this is getting me a compilation error:

Logger.h:23:17: error: default argument missing for parameter 2 of ‘static void Logger::logthis(Logger::logflag, char*, ...)’

Thanks and sorry for errors of english grammar :)).

TNHX!
According to the C++ Standard

In a given function declaration, each parameter subsequent to a parameter with a default argument shall have a default argument supplied in this or a previous declaration or shall be a function parameter pack.
A default argument shall not be redefined by a later declaration (not even to the same value). [ Example:

void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument


I hope this will help you.


For example you could declare your function the following way


static void logthis(logflag l = INFO, const char * msg = "", ...);

or

static void logthis(logflag l = INFO, char * msg = 0, ...);
Last edited on
Tnhx for the answer. I ll try..
Topic archived. No new replies allowed.