Re: Calling operator + multiple times in the same expression.
by "Thomas Tutone" <Thomas8675309@[EMAIL PROTECTED]
>
Feb 3, 2005 at 05:41 AM
BigMan@[EMAIL PROTECTED]
wrote:
[snip]
> 2. Why I need a copy ctor taking a non-const reference?
> Because I'm trying to create a type (e.g. class) that describes a
> resource wrapper. The resource is a non-copyable one (it can be
> duplicated, but one should avoid doing so for performance reasons).
This doesn't make sense. If your goal is to make the resource
non-copyable, then having a public copy constructor that takes a
non-const reference as an argument won't accomplish what you want - the
copy constructor still can be called, and having the argument as
non-const does not make it any more efficient. To make the resource
non-copyable, declare as private - but don't define - a copy
constructor that takes a const reference as an argument:
class Type {
public:
Type ( ) { }
private:
Type(const Type& ); // No definition
void operator=(const Type&); // ditto for assignments
};
Best regards,
Tom
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]