I've faced need to pass non-const static array to const argument. As I've discovered, const_cast may be used not only to remove, but also to add constness to type. So here's over-simplified version of what I'm trying to do:
int a[3] = { 1, 2, 3 };
const int b[3] = const_cast<const int[3]&>( a );
However it seems that compiler is unable to parse this with errors like
5:43: error: expected '>' before '&' token
5:43: error: expected '(' before '&' token
5:44: error: expected primary-expression before '>' token
5:50: error: expected ')' before ';' token
I've also tried to cast using pointers but got the same mistakes. Besides I don't want to switch to pointers as it would require to update quite big chunk of code.
It seems like relatively easy task, yet I'm already stuck on this for some time and wasn't able to find any useful info even remotely related to this topic.
UPD:
Thanks to comments I've found out that root cause in my case was not related to const_cast. If anyone is interested I was trying to initialise vector with list of static arrays of different sizes which apparently is not possible.
However since it was unobvious syntax of reference to array that led me to ask a question, I'm going to accept answer that explains it.
constarguments toconstparameters directly. Please show a minimal reproducible example of what you were trying to do and what error you got.cosnt_castconstcopy of your array or whether you intend to form aconstreference to the original array. Please clarify by providing a demonstration of the code that initially failed.const_cast. Could you please advise me if I should change this question or create another one for the initial issue?constness then I think adding to this question would be ok. If it is not, then I would recommend opening a new question, since changing the subject of the question would invalidate the answers that are already given. In either case make sure though that you post a complete minimal reproducible example and all error messages it generates verbatim as well as an explanation of what you originally intended to do. Also don't overwrite the code and error messages currently in this question, since that would invalidate answers as well.