Thank you for your reply. When you say "make it a global variable", you mean that I should put "a" in a header file as guestgulkan said?
However, when I put constint a = 10; in a header, and include this header in main.cpp, when I use this constant in main function like array<double, a> myArray = {}; It cannot be compiled, compiler said " 'a' is ambiguous".
Could someone tell me why and how to correct this, please?
Post your actual code - you are doing something (else) wrong.
You can put the const variable in a header file.
the word ambiguous means that you have more than one instance of the same name (maybe because you have not done your header guards)
So post your code - this should a straight forward issue to resolve.
In that case refer to my earlier post about putting the const int value in a header file and including that header file (instead of putting it in a cpp file the way you are doing it now.).
To compile array<double, a>, the compiler need to have the actual value for a at the time when it is tring to compile the function void func2(double x, array<double, a> &y)
{
......
}
extern const int a only tells the compiler that a exist somewhere - it does not give the actual value of a - and the compiler needs the actual value.