[RESOLVED] Passing too many arguments - can I make some kind of structure for these?
I had this loop
Code:
do { // Loop continues to run as long as (pcCW != 0)
.
.
.
cwR = cwRules[(loopCW * 2) + 1][pcCW]; // Fact-check at that spot
if (dbgOn && dbgStarted) {
cout << cwR << "...";
}
checkRule(cwOn, cwR, pcCW, cwWordCount, cwStage, cwLeftWord, cwRightWord, cwLineDone, pcCWRight, cwIgnore
, cwOnLeft, cwOnRight, cwDisqual, cwOptional, cwIgnoreWord, cwEndsWith, cwNot, cwInIgnore, cwFinishIgnore, cwCascade, cwInRepeat
, smarkerskt, emarkerskt, flags
, dbgOn);
if (!cwOn) {
pcCW = 0;
}
} while (pcCW != 0);
And the logic was getting too bulky - so I made that "checkRule" function - and am passing in - hopefully by reference (please someone confirm that!) - a whole lot of bool's and int's and what not.
checkRule declared like this
Code:
void checkRule(bool &cwOn, WCHAR &cwR, int &pcCW, int &cwWordCount, int &cwStage, int &cwLeftWord, int &cwRightWord, int &cwLineDone, int &pcCWRight, int &cwIgnore
, bool &cwOnLeft, bool &cwOnRight, bool &cwDisqual, bool &cwOptional, bool &cwIgnoreWord, bool &cwEndsWith, bool &cwNot, bool &cwInIgnore, bool &cwFinishIgnore, bool &cwCascade, bool &cwInRepeat
, int *smarkerskt, int *emarkerskt, short *flags
, bool &dbgOn)
{
.
.
.
}
Can I take all these bool's - for instance - and put them in some kind of structure so I am only passing one "parameter" but still getting at all these variables??
Re: Passing too many arguments - can I make some kind of structure for these?
Yes you can create a struct or a class to hold them all, and pass it instead.
Code:
class Rule
{
public:
bool cwOn;
WCHAR cwR;
// etc..
};
Re: Passing too many arguments - can I make some kind of structure for these?
Ok - I tried both STRUCT and CLASS.
I like the CONSTRUCTOR functionality of the class - that's all I needed - and I'm happily running a much smaller "main code" loop!