How to declare and use a variadic method?

R

Rui Maciel

Does anyone knows how to declare variadic methods so that they can be used to emulate printf? If
so, can you please post a small example describing how it's done?


Thanks in advance,
Rui Maciel
 
J

Juha Nieminen

James Kanze said:
That's for C; it doesn't treat the issues which come up in C++.

For C++, the answer is simply, you don't. You can only pass
PODs as varargs, which makes it pretty useless in C++.

Well, he wanted to emulate printf, and printf only supports primitive
types, so there's no problem.

If he wants to support other types, then he should use the same
approach as the C++ streams use.
 
J

James Kanze

Well, he wanted to emulate printf, and printf only supports
primitive types, so there's no problem.

Except all of the problems that printf has.
If he wants to support other types, then he should use the
same approach as the C++ streams use.

Perhaps.

One can argue about the choice of the % operator (horrible), but
boost::format supports printf like formatting with a variable
number of arguments (but in a typesafe way); many years ago, so
did my GB_Format (using a completely different technique than
boost::format).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top