Jump to content
  • Advertisement
Sign in to follow this  
lride

passing variadic arguments

This topic is 1233 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!