Results 1 to 3 of 3

Thread: [RESOLVED] Passing too many arguments - can I make some kind of structure for these?

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [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??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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..
    };
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width