GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 111 of 190    Print  
Class X
{

X(){}
X(X &obj)
{}

// supose '=' operator is also overloaded for this class. I am not writing code for that
}

main()
{

X a;
X b = a;
X c(&a);
X d;
d = a;

}


What is the difference between a, b, c, d objects ?



  
Total Answers and Comments: 3 Last Update: December 07, 2008     Asked by: smart_coder 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 06, 2007 08:31:23   #1  
Rajesh        

RE: Class X{X(){}X(X &obj)
X b = a; --calls copy constructor as here new object will be created.X c(a); copy constructord = a; normal assignment so = operator comes into picture.
 
Is this answer useful? Yes | No
February 20, 2007 03:47:23   #2  
swetha        

RE: Class X{X(){}X(X &obj)

x a;  -  calls default constructor

X b = a;  - calls copy constructor
X c(a);    - calls copy constructor
X d;       - calls default constructor
d = a;    -   calls overloaded = operator.


 
Is this answer useful? Yes | No
December 07, 2008 10:27:25   #3  
burraganesh Member Since: December 2008   Contribution: 21    

RE: Class X{X(){}X(X &obj){} // supose '=' operator is also overloaded for this class. I am not writing code for that }main(){X a;X b = a;X c(&a);X d;d = a;}What is the difference between a, b, c, d objects ?
For statements Xb =a and X c(a) copy constructor is invoked but with assignment d=a,operator()= is invoked.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape