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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:22:38+00:00 2026-06-13T08:22:38+00:00

I am little new to C++, I have one doubt in variable argument passing.

  • 0

I am little new to C++, I have one doubt in variable argument passing. As I mentioned in a sample code below ( This code won’t work at all, just for others understanding of my question I framed it like this), I have two functions func with 1 parameter and 2 parameters(parameter overloading). I am calling the func from main, before that I am checking whether I needs to call 2 parameter or 1 parameter. Here is the problem, as I know I can call two functions in respective if elseif statements, but I am curious to know whether I can manage with only one function. (In below code I am passing string not int, as I mentioned before this is just for others understanding purpose.

#include<iostream.h>
#include <string>

void func(int, int);
void func(int);

void main()
{
   int a, b,in;

   cout << "Enter the 2 for 2 arg, 1 for 1 arg\n";
   cin << in;

   if ( in == 2)
   { 
      string pass = "a,b";
   }
   elseif ( in == 1)
   {
      string pass = "a";
   }
   else
   {
      return 0;
   }

   func(pass);

   cout<<"In main\n"<<endl;
}

void func(int iNum1)
{
   cout<<"In func1 "<<iNum1<<endl;
}

void func(int iNum1, int iNum2)
{
   cout<<"In func2 "<<iNum1<<" "<<iNum2<<endl;
}
  • 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-13T08:22:39+00:00Added an answer on June 13, 2026 at 8:22 am

    You may use stdarg method as explained by Ronald. Or you could use a function that takes a vector of arguments. Push the arguments to the vector first and then call following func:

    func(const vector<int>& argv) {
      for (vector<int>::const_iterator iter = argv.begin(); iter != argv.end(); ++iter) {
        // Get the arguments
      }
      // Do what you want ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem. This is my code: stackPanelShapesContainer = new StackPanel(); InitializeStackPanle();
I have a little doubt about javascript, a new language that I'm studying... I
I have one little problem...Here is my code..Is there a way to distribute weights
I'm a little new to C#, so bear with me on this one... Okay,
I'm a little new to javascript. I have a bunch of checkboxes for an
I'm a little new with SQL so bear with me. I have two tables,
I am having a new little problem; I have a little pointer called: int
I'm new around here and i have a little problems with a C# application.
am new to Json so a little green. I have a Rest Based Service
I'am new to Python 3 and could really use a little help. I have

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.