copy constructor calling

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

copy constructor calling

 
0
  #1
Feb 9th, 2009
If an explicit copy constructor is defined that makes a complex copy, does:
  1. int main()
  2. {
  3. class shoe shoe1;
  4. class shoe shoe_copy(shoe1);
  5. }
And
  1. int main()
  2. {
  3. class shoe shoe1;
  4. class shoe shoe_copy;
  5. shoe_copy=shoe1;
  6. }
Basically I'm asking if the assignment operator accesses the complex copy constructor as an initialization of a class object to another class object would.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 675
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 100
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: copy constructor calling

 
1
  #2
Feb 9th, 2009
Well I dont think it would work out. Basically constructors should be members of that particular class or if you design it explicitly it will become a function with the same name of the class and will produce out an error.

If you wish to make the above methods work out . You will have to again call out the function from the constructors of your class for it to work.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: copy constructor calling

 
1
  #3
Feb 9th, 2009
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 46
Reputation: kbshibukumar is an unknown quantity at this point 
Solved Threads: 7
kbshibukumar kbshibukumar is offline Offline
Light Poster

Re: copy constructor calling

 
1
  #4
Feb 9th, 2009
only the first example invokes copy constructor. If the second one needs to work in the same manner as copy constructor does, you have to overload the assignment operator.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

Re: copy constructor calling

 
0
  #5
Feb 9th, 2009
Thank you Sky Diploma, jencas, and kbshibukumar the site and your advice was very helpful. So basiclly what you were all saying was that the copy constructor and assignment operator are 2 different functions that must be defined by the coder seperately. I think that there is an automatic version of the overloaded assignment operator but it may be compiler dependant-I have one with Visual studio prfessional 2008.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC