943,779 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1383
  • C++ RSS
Feb 9th, 2009
0

copy constructor calling

Expand Post »
If an explicit copy constructor is defined that makes a complex copy, does:
C++ Syntax (Toggle Plain Text)
  1. int main()
  2. {
  3. class shoe shoe1;
  4. class shoe shoe_copy(shoe1);
  5. }
And
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008
Feb 9th, 2009
1

Re: copy constructor calling

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.
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008
Feb 9th, 2009
1

Re: copy constructor calling

Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Feb 9th, 2009
1

Re: copy constructor calling

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.
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
kbshibukumar is offline Offline
65 posts
since Jan 2009
Feb 9th, 2009
0

Re: copy constructor calling

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Making a krypto like game in C++
Next Thread in C++ Forum Timeline: Calculating Error Gradient in a Neural Network





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC