Re: Traverse Function?


[ Follow Ups ] [ Post Followup ] [ CS2604 Discussion WWWBoard ] [ FAQ ]

Posted by Sleepless Snowman on July 21, 1999 at 00:31:48:

In Reply to: Traverse Function? posted by Fuzzo on July 20, 1999 at 21:45:25:

Without giving away too much and violating the honor code, here is (hopefully) a clear explanation as to what "wl->Traverse (&ShowWindow)" means...however, i think the following example will perhaps shed on light on the subject...

given a function:

void dosomething(int whatever)
{
whatever=whatever+1;
}

when you invoke function with the following:

int stupid=69; //everyone's favorite test variable :)

dosomething(stupid);

stupid is passed in, but internally to the function, the value of stupid 'becomes' whatever. Whatever, is incremented by 1.

in the case of "wl->Traverse (&ShowWindow);"
same idea is applied... however, go back to the interface defintion for Traverse()

void WindowList::Traverse(void (*Visit) (Window *))

the method Traverse is expecting some sort of parameter... in this case however, is a pointer to a function that has no return type, and that the function that is being referenced by the pointer has a parameter, and it is expecting a pointer to a window object...

it's just like a regular function...however, instead of passing in values, you pass in functions...

the name that you use for the parameter when passing into functions, is what you would use internally to write the function...

look again at:

void dosomething(int whatever)

and that whatever, wasn't a variable...but a function...write the code the same way you would for a variable...

hope that helps... :)


i hope that made things clear rather than murkier...


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2604 Discussion WWWBoard ] [ FAQ ]