PDA

Click to See Complete Forum and Search --> : optional parameters (without overriding)


nabeels786
Apr 25th, 2002, 04:27 PM
is there a way to do it without having to override the function?

Zaei
Apr 25th, 2002, 05:04 PM
In a prototype:

void func(int x=0);

x's default value will be 0. the actual function definition might look like this:

void func(int x)
{
cout << x << endl;
}

Note the lack of the =0. If you dont have the prototype, then you DO need to ad the =0 though.

Z.

nabeels786
Apr 25th, 2002, 08:17 PM
i have to have a prototype?

cant just do

void test(int num=0){
//blah blah
}

Zaei
Apr 25th, 2002, 09:19 PM
You dont have to have the prototype, but f you do, only have the =0 in that prototype.

Z.