G
gopal
Hi, i am now reading thru the thinking in C++ and i have some doubts at
section CONST REFERENCES as
The use of const references in function arguments is especially
important because your function may receive a temporary object.
This might have been created as a return value of another function
or explicitly by the user of your function. Temporary objects are
always const, so if you don't use a const reference, that argument
won't be accepted by the compiler. As a very simple example,
page - 498 , chapter 11, Ref & Copy ctor,
can any pls make me understand this. I tried reading thru again &
again, but i am not able to understand. This was foll by example which
i could not understand
//: C11:ConstReferenceArguments.cpp
// Passing references as const
478 Thinking in C++ www.BruceEckel.com
void f(int&) {}
void g(const int&) {}
int main() {
//! f(1); // Error
g(1);
} ///:~
Pls clarify
Regards
JK
section CONST REFERENCES as
The use of const references in function arguments is especially
important because your function may receive a temporary object.
This might have been created as a return value of another function
or explicitly by the user of your function. Temporary objects are
always const, so if you don't use a const reference, that argument
won't be accepted by the compiler. As a very simple example,
page - 498 , chapter 11, Ref & Copy ctor,
can any pls make me understand this. I tried reading thru again &
again, but i am not able to understand. This was foll by example which
i could not understand
//: C11:ConstReferenceArguments.cpp
// Passing references as const
478 Thinking in C++ www.BruceEckel.com
void f(int&) {}
void g(const int&) {}
int main() {
//! f(1); // Error
g(1);
} ///:~
Pls clarify
Regards
JK