Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: All
Nov 27, 2000

Copy Constructor's Signatures

C++ defines four possible forms for a class's copy constructor. For a class called X, a copy constructor can have one of the following forms:

 
X(X&);
X(const X&);
X(volatile X&);
X(const volatile X&);

Note that the copy constructor's parameter cannot be passed by value. Therefore, the following forms are all illegal:

 
X(X); // error, pass by value
X(const X); // ditto
X(X*); // error, only references are allowed

A copy constructor can have only one parameter; additional parameters are allowed only if they have default values. For example:

 
X(const X&, int n=0); // OK, 2nd param has a default value
X(const X&, int n=0, void *p=NULL); // ditto
X(const X&, int n); // Illegal
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date