Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Leda > Re: Calling ope...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 8 Topic 188 of 212
Post > Topic >>

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! ]
 




 8 Posts in Topic:
Calling operator + multiple times in the same expression.
BigMan@[EMAIL PROTECTED]   2005-02-01 15:09:17 
Re: Calling operator + multiple times in the same expression.
"Abhishek Pamecha&qu  2005-02-01 18:23:20 
Re: Calling operator + multiple times in the same expression.
Victor Bazarov <v.Abaz  2005-02-01 18:28:35 
Re: Calling operator + multiple times in the same expression.
"Thomas Mang" &  2005-02-01 18:27:29 
Re: Calling operator + multiple times in the same expression.
BigMan@[EMAIL PROTECTED]   2005-02-02 15:02:26 
Re: Calling operator + multiple times in the same expression.
"Thomas Tutone"  2005-02-03 05:41:22 
Re: Calling operator + multiple times in the same expression.
kanze@[EMAIL PROTECTED]   2005-02-03 10:19:34 
Re: Calling operator + multiple times in the same expression.
"Thomas Mang" &  2005-02-05 20:44:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:48:11 CDT 2008.