How do I create a function which accepts a variable argument list in C++/CLI? I am looking to create a function which forwards most of it's arguments to String::Format
.
views:
269answers:
1
+5
A:
Declare the last argument as a managed array prefixed with an ellipsis.
Here is a variable argument function that just passes all of its arguments to String::Format
String ^FormatAString(String ^format, ...array<Object^> ^args)
{
return String::Format(format, args);
}
And here is how to call it:
Console::WriteLine(FormatAString(L"{0} {1} {2}.", 40.5, "hello", DateTime::Now));
Joe Daley
2009-12-01 12:21:32