• Advertisement
Sign in to follow this  

passing variadic arguments

This topic is 1056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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??

Share this post


Link to post
Share on other sites
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.
}
Edited by Servant of the Lord

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement