I'm a beginner. Can anybody help me?
What is " const reference" in C++? How can I use it?
Do you mean like a const pointer or const variable?
The 'const' keyword tells the compiler that the variable following the 'const' will not change.
It is a safety measure for your sake. If you mistakingly try to modify a 'const' variable in your program, the compiler will issue an error when you compile the code.
Examples:
const char a=15; // constant char
const char hello[]="hello!"; // constant string
const char *bah=%26amp;a; // constant pointer to a
Reply:I mean a const reference in functions, for example : ErrorCode Stack%26lt;Entry%26gt;::push(const Entry %26amp;item); after 3 days thinking, finally, I get the answer, const reference is 50% like value reference and the rest 50%, it's like a reference Report It
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment