* Victor Bazarov:
huangshan wrote:
>hi all
I read "C++ Primer, Fourth Edition" ,
but can't understand this sentence
"By making the parameters const references, we allow types that do
not allow copying."
in "16.1. Template Definitions" .
who can tell me?
class NoCopies {
NoCopies(NoCopies const&); // copying prohibited
public:
NoCopies(int);
};
void foo(NoCopies);
void bar(const NoCopies&);
int main()
{
NoCopies nc(42);
foo(nc); // error -- must be able to copy
bar(nc); // no error
}
Just to fill out the picture, the /current/ standard doesn't allow
bar( NoCopies( 42 ) );
because in the current standard, when binding a temporary to a reference
to const, the compiler is allowed to copy the temporary any number of
times, i.e. a copy constructor must be available.
So the phrasing "allow types that do not allow copying" allows an
interpretation where one believes more is allowed than is actually
allowed, but, types that do not allow copying are allowed as far as the
current standard allows (heh).
As I understand it this will be fixed in C++0x.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?