Try compiling the following program: void foo(const int *); int main() { int. v. new int [10); foo(); return 0; 1 The co
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Try compiling the following program: void foo(const int *); int main() { int. v. new int [10); foo(); return 0; 1 The co
Try compiling the following program: void foo(const int *); int main() { int. v. new int [10); foo(); return 0; 1 The compiler will give you an error because you are converting into to const into the error message looks like this with gec 11.2.8: test.cpp: In function 'int main': test.cpp:5:7: error: invalid conversion from 'int' to 'const int**' [-fpermissive] 5.1 foo(); inte test.cpp:1:10: note: initializing argument 1 of 'void foo(const int +)' 1 | void foo(const intes); Usually it is possible to convert from non-const to const - why is that not possible here? Hint. It is obvious why the following program does not compile: const int bar 0); int main() { intv = new int [10]; V[O] - bar(); return 8; } What does this program have in common with the program above?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!