I am writing a function called Evaluate
in C++. It accepts three arrays as parameters:
double Evaluate (double inputs[], double hidden[], double outputs[]) {
// To-Do...
}
The problem appears in this scenario:
The programmer decides to initialize the function
Evaluate
with only two parameters: inputs[] and outputs.
So, I was thinking of creating Evaluate
like this:
double Evaluate (double inputs[], double hidden[] = {}, double outputs[]) {
// To-Do...
}
But, this creates strange Errors:
In function 'double Evaluate (double*, double*, double*)'
34:53: error: unexpected '{' token
34:54: error: unexpected '}' token
Is there a solution?
*Thanks in advance.
I have managed to use my answer with the help in the comments.
I am currently curious, won't multiple function overloads cause the program to get slower?
One way which I have learnt is function overloading - where you create copy of the same function, but in different ways.
int add(int a)
{
return ++a;
}
int add(int a, int b)
{
return a + b;
}
double add(double a, double b)
{
return a + b;
}
This became so helpful that I'm able to implement many operations with it!
In terms of my evaluate
function, I could do:
evaluate(std::vector<double> inputs, std::vector<double> outputs, std::vector<double> hidden)
{
// ...
}
evaluate (std::vector<double> inputs, std::vector<double> outputs)
{
// ...
}