![]() |
|
#1
|
||||
|
||||
copy constructor and return valuesSuppose I have a function as follows:
return_type func( ... args ... ) { return_type T; . . . return T; } The line "return T;" will call the copy constructor for the class return_type. Now suppose I have the following line of code: return_type T(func(... args ...)); Again, the copy contructor is being called to initialize T. Does that mean that the copy contructor will be called twice, or will the compiler recognize this and deal with it? I'm using Borland C++ Builder X, Windows XP, if it matters. |
|
#2
|
|||
|
|||
Re: copy constructor and return valuesQuote:
Why don't you make a simple test program and see what happens? Maybe something like: CPP / C++ / C Code:
My output: Code:
Now, I'm not sure that this is exactly what you had in mind, but that is kind of the point: You have two wonderful tools at your own location. I will list them in reverse alphabetical order: 1. Your compiler 2. Your brain The other important tool is somewhat remote (a programming assistance forum on the internet). It's always OK to ask, but sometimes it is faster (and more edifying) to explore on your own. (Faster, I claim, than posting a request for help and waiting for a helpful response.) Regards, Dave "The little gray cells, Hastings; the little gray cells." ---Hercule Poirot |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The