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, 2732👍, 0💬
Popular Posts:
What is a delegate ? Delegate is a class that can hold a reference to a method or a function. Delega...
How comfortable are you with writing HTML documents entirely by hand? Everyone has a different prefe...
What is the concept of XPOINTER? XPOINTER is used to locate data within XML document. XPOINTER can p...
How To Assign Query Results to Variables? - Oracle DBA FAQ - Working with Database Objects in PL/SQL...
What is the output of printf("%d")? 1. When we write printf("%d",x); this means compiler will print ...