Re: Make assign illegal for class



On Sat, 20 Aug 2005 21:05:20 +0100, "Mark Randall"
<markyr@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

>Hi,
>
>Is there any way to explicitly make = or copy construction illegal for a
>given class? I have several that are most complex and will at no point ever
>need to be copied.
>
>For integrity purposes, is there any way to disable the copy all together
>and generate a warning? (I was thinking of having a home made copy
>constructor but I have no idea about generating a compile error inside it).

Declare them private but don't ever define them, e.g.

class X
{

private:

// Copyguard
X(const X&);
void operator=(const X&);
};

--
Doug Harrison
VC++ MVP
.



Relevant Pages

  • Re: Data Object Collection Inheritance
    ... > private System.Windows.Forms.ListBox listBox1;> private System.Windows.Forms.Button cmdID;> private System.Windows.Forms.Button cmdText; ... > private void InitializeComponent() ... > // TODO: Add BaseDataCollection.IsReadOnly getter implementation> return false; ... > public sealed class SubClassCollection: ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Problem in converting to C#
    ... public delegate void delegate1 ... private void InitializeComponent() ... private void Button1_Click(object sender, System.EventArgs e) ... Private Sub Form1_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Redraw problem - please help
    ... >> public int CurrentX; ... >> public void Create ... >> private System.ComponentModel.IContainer components; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Law of Demeter can be supported without eliminating object coupling
    ... void C::M ... // do something to change solution state ... or there is a disconnect here as well. ...
    (comp.object)
  • Re: GPS Library - Listed Here
    ... > public string Longitude_Sexagesimal ... > private States state; ... > public StatusType GpsStatus ... > public void Start ...
    (microsoft.public.dotnet.framework.compactframework)