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 8107099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:39:55+00:00 2026-06-06T00:39:55+00:00

I’ve got the class member: LineND::LineND(double a …) { coefficients.push_back(a); va_list arguments; va_start(arguments, a);

  • 0

I’ve got the class member:

LineND::LineND(double a ...)
{
    coefficients.push_back(a);
    va_list arguments;
    va_start(arguments, a);
    double argValue;
    do
    {
        argValue = va_arg(arguments, double);
        coefficients.push_back(argValue);
    }while(argValue != NULL);   // THIS IS A PROBLEM POINT!
    va_end(arguments);
}

I don’t know how many arguments will be used. I need to take each argument and put it into the vector called coefficients. How should I do that? I understand, that the statement while(argValue != NULL) is not correct in this case. I can’t use for example this signature:

LineND::LineND(int numArgs, double a ...)

to change the condition like this:

while(argValue != numArgs);

The point is I can’t change the signature of the method. Need to resolve this problem another way.

  • 1 1 Answer
  • 0 Views
  • 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-06-06T00:39:56+00:00Added an answer on June 6, 2026 at 12:39 am

    Variable argument lists have several drawbacks:

    • Callers can pass in everything they want.
    • If a non-POD object is passed, undefined behaviour is summoned
    • You can’t rely on the number of arguments (the caller can make errors)
    • You put a LOT of responsibility on your CLIENT, for whom you intended to have an easier time with your library code (practical example: format-string-bugs/-errors)

    Compared to variadic templates:

    • Compile time list size is known
    • Types are known at compile time
    • You have the responsibility for stuff, not your client, which is like it should be.

    Example:

    void pass_me_floats_impl (std::initializer_list<float> floats) {
        ...
    }
    

    You can put this into the private section of a class declaration or in some detail namespace. Note: pass_me_floats_impl() doesn’t have to be implemented in a header.

    Then here’s the nice stuff for your client:

    template <typename ...ArgsT>
    void pass_me_floats (ArgsT ...floats) {
        pass_me_floats_impl ({floats...});
    }
    

    He now can do:

    pass_me_floats ();
    pass_me_floats (3.5f);
    pass_me_floats (1f, 2f, 4f);
    

    But he can’t do:

    pass_me_floats (4UL, std::string());
    

    because that would emit a compile error inside your pass_me_floats-function.

    If you need at least, say, 2 arguments, then make it so:

    template <typename ...ArgsT>
    void pass_me_floats (float one, float two, ArgsT... rest) {}
    

    And of course, if you want it a complete inline function, you can also

    template <typename ...ArgsT>
    void pass_me_floats (ArgsT... rest) {
        std::array<float, sizeof...(ArgsT)> const floaties {rest...};
    
        for (const auto f : floaties) {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string

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.