passing variadic arguments

Started by
1 comment, last by lride 9 years, 1 month ago

struct A
{
	A(){}
	A(int i, std::string s){}
	A(std::string  s){}
};

A createA(...)
{
	return A(...);

}

int main()
{
        createA();
	createA(1, "zz");
	createA("zz");
}

I'm getting error C2143: syntax error : missing ')' before '...'

why??
An invisible text.
Advertisement

What language are you using?

If C++, it needs to be a templated function, and you do it like this:


template<typename ...Args> //Take a variable number of template arguments.
A createA( Args&& ...args ) //Accept the variable number of arguments by 'universal reference' (const ref, ref, or rvalue ref).
{
	return A( std::forward<Args>(args)... ); //Forward their current reference type, and unroll the arguments.
}

c++

thanks!

An invisible text.

This topic is closed to new replies.

Advertisement