I have this overloaded functions:
CString TestFunction(CString s, int number, int optPar1 = 123, int optPar2 = 456) //...
CString TestFunction(int index, CString s, int numbers[], int optPar1 = 123, int optPar2 = 456) //...
CString TestFunction(CString s, int numbers[], int optPar1 = 123, int optPar2 = 456) //...
When I do this:
1st case:
CString s = TestFunction(someString, anArrayOfIntsWithValues);
2nd case:
for (int i =0; i < max; i++)
{
CString s = TestFunction(i, someString, anArrayOfIntsWithValues);
}
It gives me:
On the 1st case:
error C2664: 'CString Class1::TestFunction(CString, int, int, int)' : cannot convert parameter 2 from 'const int [2]' to 'int'
5 IntelliSense: no instance of overloaded function "Class1::TestFunction" matches the argument list
On the 2nd case:
Error 2 error C2664: 'CString Class1::TestFunction(CString, int,int,int)' : cannot convert parameter 1 from 'int' to 'CString'
6 IntelliSense: no instance of overloaded function "Class1::TestFunction" matches the argument list
I am new to C++ and I don't know what is wrong with this code, but it was perfectly compiled in C# (with the knowledge of overloaded functions and optional parameters).
Note: this is just a representation of the real code - user-defined types are used as parameters.
EDIT: added a second case and 1st case was already answered.
[]in parameter list is archaic and actually the array is not passed by value . So this may differ from your expectations if you are coming from other languages