IBM Support

Reference to a non-const object cannot be initialized with an r-value of that object

Question & Answer


Question

My program fails to compile with an error message indicating that a reference to a non-const object cannot be initialized with an r-value of that object. What is the rationale behind this compiler behavior?

[{"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Component":"Compiler","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF022","label":"OS X"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Component":"Compiler","Platform":[{"code":"PF002","label":"AIX"}],"Version":"All Versions","Edition":"Not applicable","Line of Business":{"code":"LOB73","label":"Power TPS"}},{"Product":{"code":"SSXVZZ","label":"XL C\/C++ for Linux"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Component":"Compiler","Platform":[{"code":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"Not Applicable","Line of Business":{"code":"LOB73","label":"Power TPS"}}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

More support for:
XL C/C++

Software version:
All Versions

Operating system(s):
AIX, Linux, OS X

Document number:
335179

Modified date:
06 December 2018

UID

swg21153090