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, 2952👍, 0💬
Popular Posts:
How do I use a scriptlet to initialize a newly instantiated bean? A jsp:useBean action may optionall...
What is the significance of Finalize method in .NET? .NET Garbage collector does almost all clean up...
How To Select Some Rows from a Table? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY If yo...
Can include files be nested? The answer is yes. Include files can be nested any number of times. As ...
.NET INTERVIEW QUESTIONS - What are types of compatibility in VB6? There are three possible project ...