Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is a COPY CONSTRUCTOR and when is it called?
What is a COPY CONSTRUCTOR and when is it called?
✍: fyicenter.com
A copy constructor is a method that accepts an object of the same class and copies it’s data members to the object on the left part of assignement:
class Point2D{
int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor
public Point2D( const Point2D & ) ;
};
Point2D::Point2D( const Point2D & p )
{
this->x = p.x;
this->y = p.y;
this->color = p.color;
this->pinned = p.pinned;
}
main(){
Point2D MyPoint;
MyPoint.color = 345;
Point2D AnotherPoint = Point2D( MyPoint ); // now AnotherPoint has color = 345
2012-02-14, 2594👍, 0💬
Popular Posts:
Write an equivalent expression for x%8? x&7
What Tools to Use to View HTML Documents? The basic tool you need to view HTML documents is any Web ...
What is the result of using Option Explicit? When writing your C program, you can include files in t...
what are the advantages of hosting WCF Services in IIS as compared to self hosting? There are two ma...
How can you raise custom errors from stored procedure ? The RAISERROR statement is used to produce a...