Interesting C++function signature
Hello there!
Here's a recent one (which is perhaps strange) I found that in C++ it is possible to set function signatures in a similar way:
BOOL PrintMsg(HANDLE hOut,...)
{
}
What is a colon after a comma? Unlimited number of parameters? If so, what variable is it set to, i.e. how to access them? Can you please explain?
Thanks!
1
2 answers
This property of the language is inherited from the C language. In the same way, functions with a variable number of parameters of the type printf, etc. are formed. This is done using macros va_arg, va_end, va_start
.
4
Author: stanislav, 2012-10-12 17:22:44
Here is a usage example.
int function_(int first , ...)
{
std::cout << "\nпервый=" << first;
int * arguments = &first; // получаем адрес первого аргумента
arguments++; // увеличиваем адрес указателя
std::cout << "\nвторой=" << *arguments;
arguments++;
std::cout << "\nтретий=" << *arguments;
return 1;
}
int main()
{
std::system("chcp 1251");
function_(5 , 7 , 10);
}
0
Author: manking, 2012-10-12 18:46:59