| | |
copy constructor calling
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
If an explicit copy constructor is defined that makes a complex copy, does:
And
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.
C++ Syntax (Toggle Plain Text)
int main() { class shoe shoe1; class shoe shoe_copy(shoe1); }
C++ Syntax (Toggle Plain Text)
int main() { class shoe shoe1; class shoe shoe_copy; shoe_copy=shoe1; }
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.
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.
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
May be this is helpful for you: http://www.fredosaurus.com/notes-cpp...structors.html
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
Please use code tags - Please mark solved threads as solved
•
•
Join Date: Jan 2009
Posts: 46
Reputation:
Solved Threads: 7
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.
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
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.
![]() |
Similar Threads
- Default copy constructor (C++)
- Program crashing, need good debugger (C++)
- which one is better (C++)
- Adding memberfunctions into a class? (C++)
- Classes (C++)
- template array initialization (C++)
- Constructor and Convertion operator are the same,how to avoid memory leak? (C++)
Other Threads in the C++ Forum
- Previous Thread: Making a krypto like game in C++
- Next Thread: Calculating Error Gradient in a Neural Network
| Thread Tools | Search this Thread |
add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory microsoft multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





