Thursday, November 12, 2015

C++ : copy constructor

We already know the basic constructor utility which is : initializing internal members. If not constructor is specified, the default constructor initializes each of class' members with their constructor.

Now let's take a look to the copy constructor :

Point (const Point & p);

This constructor will initialize our object by copying another one :

Point p1 (otherPoint);

Note: It is also possible to define our own copy constructor to define more specifically which members should be copied.

Cem SOYDING

Author & Editor

Senior software engineer with 12 years of experience in both embedded systems and C# .NET

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

 
biz.