Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87281
  • 博文数量: 60
  • 博客积分: 4002
  • 博客等级: 中校
  • 技术积分: 645
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 18:11
文章分类

全部博文(60)

文章存档

2011年(60)

我的朋友

分类: C/C++

2011-03-30 21:33:22


      A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an  existing object. The first argument of such a constructor is a reference to an object of the same type as is being constructed (const or non-const), which might be followed by parameters of any type(all having default values).

      Normally the compiler automatically creates a copy constructor for each class (known as a default copy constructor) but for special cases the programmer creates the copy constructor, known as a user-defined copy constructor, In such case, the complier doesnot create one.

      A user-defined copy constructor is generally needed when an object owns pointers or non-shareable reference, such as to a file, in which case a destructor and an assignment operator should also be written.

阅读(199) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~