| ab123 (10) | |
|
Can some one tell me what does the following line mean? const Array<int>& abc; then I want to assign abc = foo->get_array() where get_array() returns me a const reference to an array of ints. I get an error saying reference variable "abc" requires an initializer when I declare it. How can I use the function get_array() and assign its return value to a variable? Also, If I write const Array<int>& abc = foo->get_array(); this seems to work fine. However I want to declare abc first and then use it. Can some one help me here pls! | |
|
|
|
| ab123 (10) | |
| FYI: This is not the standard library array that I am using. | |
|
|
|
| toum (205) | ||||
const Array<int>& abc; declares a reference to a const object of type Array<int>
A const object must be assigned to when it's created. You can't modify it later, otherwise it wouldn't be const.
Then you can not declare it const. | ||||
|
|
||||
| ab123 (10) | |
| Thanks! :) That helped. | |
|
|
|