Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 660109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:07:11+00:00 2026-05-13T23:07:11+00:00

is it possible to construct variadic arguments for function by overloading operator comma of

  • 0

is it possible to construct variadic arguments for function by overloading operator comma of the argument? i want to see an example how to do so.., maybe something like this:

template <typename T> class ArgList {
public:
    ArgList(const T& a);
    ArgList<T>& operator,(const T& a,const T& b);
}
//declaration
void myFunction(ArgList<int> list);

//in use:
myFunction(1,2,3,4);

//or maybe:
myFunction(ArgList<int>(1),2,3,4);
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:07:12+00:00Added an answer on May 13, 2026 at 11:07 pm

    It is sort-of possible, but the usage won’t look very nice. For exxample:

    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <iterator>
    
    template <class T>
    class list_of
    {
        std::vector<T> data;
    public:
        typedef typename std::vector<T>::const_iterator const_iterator;
        const_iterator begin() const { return data.begin(); }
        const_iterator end() const { return data.end(); }
    
        list_of& operator, (const T& t) {
            data.push_back(t);
            return *this;
        }
    };
    
    void print(const list_of<int>& args)
    {
        std::copy(args.begin(), args.end(), std::ostream_iterator<int>(std::cout, " "));
    }
    
    int main()
    {
        print( (list_of<int>(), 1, 2, 3, 4, 5) );
    }
    

    This shortcoming will be fixed in C++0x where you can do:

    void print(const std::initializer_list<int>& args)
    {
        std::copy(args.begin(), args.end(), std::ostream_iterator<int>(std::cout, " "));
    }
    
    int main()
    {
        print( {1, 2, 3, 4, 5} );
    }
    

    or even with mixed types:

    template <class T>
    void print(const T& t)
    {
        std::cout << t;
    }
    
    template <class Arg1, class ...ArgN>
    void print(const Arg1& a1, const ArgN& ...an)
    {
        std::cout << a1 << ' ';
        print(an...);
    }
    
    
    int main()
    {
        print( 1, 2.4, 'u', "hello world" );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming it's possible, how would one pass arguments by reference to a variadic function
Is something like the following construct possible? public IQueryable<T> AllWithFetch<TRelated>(IQueryable<T> existing, params Expression<Func<T, TRelated>>[]
Possible Duplicate: How does the (function() {})() construct work and why do people use
Possible Duplicate: What is the (function() { } )() construct in JavaScript? I came
Is it possible to construct a numpy matrix from a function? In this case
Is it possible to construct a parameterized class in Matlab? For example in Java
Is it possible to construct function call (inside function template) with variable number of
Is it possible to construct an vertical sliding thumbnails of images. The example is
Is it possible to construct a scope like this User.where(:id => [5,4,3,2,7,1000] ) in
As question stated, would like to know is that possible to construct jQuery object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.