I have a class that defines a function with default parameters. It works fine as long as function definition is in header file before function that calls it.
However if I move it after the calling function C++ Builder (2010) reports Too few parameters error.
header might be for example:
class TSomething
{
public:
void CallingFunction();
void Function(int a);
}
and cpp file might be:
#include "Header.h"
TSomething::CallingFunction()
{
Function(); // "Too few arguments" here...
}
TSomething::Function(int a = 123)
{
//... some code here ...
}
So if calling function is before "Function" it reports Too few parameters. I do not understand why because it includes function definition in #include statement in cpp file. Can anyone tell me how to rearrange this so it accepts properly default arguments? I can move the Function(int a) above the CallingFunction to make it work so far.
You need to put the default arguments in member function's declaration inside your class:
Also, remove the default arguments from the definition outside of your class.