grouping function parameters?

Hi all,

I have a function that is used MANY times through out my program. This function takes multiple parameters. However, these parameters vary depending of there placement within the program.

For example, I might have these:

1. myFunction(string1, boolA, boolB, textBox1, textBox2){}
2. myFunction(string2, boolB, boolC, textBox3, textBox4){}
3. myFunction(string3, boolD, boolE, textBox5, textBox6){}

Is there a way to group the parameters and store them for later use? For example (using the above example):

1. myFunction(parameterGroup1){}
2. myFunction(parameterGroup2){}
3. myFunction(parameterGroup1){}

Where parameterGroup1 = string1, boolA, boolB, textBox1, textBox2... etc etc.

I would be very appreciative if someone could help me with this! This would help simplify my code a great deal...

Not sure if this is even possible...

Thanks,
Last edited on
Hi Zhuge,

Thanks for the reply and the links. I haven't used struct or classes yet but I'm starting to see that I could use them within my program.

I have had a go at using structures but I'm having no luck. Perhaps I need to give some more information....

I have all my functions in Functions.h and these functions are called in the Form1_Load event of a windows form application. So for example, in Functions.h I have:

1
2
myFunction(System^ string1, bool boolA(const std::string & str),  bool boolB(const std::string & str), TextBox^ textBox1, TextBox^ textBox2)
 {...the rest of the code goes here...}


And in Form1.h (in the Form1_Load event):

myFunction(string1, boolA, boolB, textBox1, textBox2);

I tried the following:

1
2
struct test{
System^ string1; bool boolA(const std::string & str);  bool boolB(const std::string & str); TextBox^ textBox1; TextBox^ textBox2;};


And using this with myFunction()...:

myFunction(test);

Obviously, this attempt didn't work....Not sure why...

Thanks,
Last edited on
Topic archived. No new replies allowed.