hi eveybody.
i have a question.plz help me.
can i use dynamics aray for argumant in function,in another way i wanna have a function and i wanna the number of my argumant not be constan,how can i do that,its possible?
#include <iostream>
#include <vector>
void func(std::vector<int>& p1, std::vector<double>& p2, std::vector<std::string>& p3)
{
//here is used type void; obviously may use another C++ type
int integer1 = 7 * p1[2]; //using the 3rd integer to
p1.push_back(integer1); //pass it as the 4th in the p1[]
double double1 = 3. * p2[0];//the same with the double
p2.push_back(double1); //in the p2[] values
std::string proverb = p3[1] + p3[2] + p3[3];
p3.push_back(proverb); //and with the strings
//---------------your code-------------------
}
int main()
{
std::vector<int> params1; //declaring a list with integers(if necessary)
params1.push_back(1);
params1.push_back(-12); //filling the list with some values
params1.push_back(34); //how many are necessary
std::vector<double> params2;//declaring another type of variables
params2.push_back(1.234); //(if necessary)
params2.push_back(2.345); //filling it
std::vector<std::string> params3;// if necessary another list of variables
params3.push_back("Hello world!");// of string type
params3.push_back("All is ");
params3.push_back("well when ");
params3.push_back("ends well!..");
func(params1, params2, params3);//calling the function
std::cout << params1[3] << '\t' << params2[2] << "\n\n";
std::cout << params3[0] << "\n\n";
std::cout << params3[4] <<'\n';//verifying that called function works
//here you can change the values(and the number) of the variables in the lists
//params1/params2/params3 for a new call of the function.
return 0;
}
238 3.702
Hello world!
All is well when ends well!..