Functions
-
Hi Can someone please help me with this. :( Given the following-> Write a function called Copy, witch takes two parameters of type string. The first par is your Source(string to be copied) second is your Dest string(target) this function need not return anything(NOT ALLOWED TO USE strcpy) I need to show how i would use this function(call) by writing code that copy one string into another. A deep copy should take place not Shallow. How can i implement the following in my function clear, erase, resize, append and index operator. How does the following piece of code look?
#include #include using namespace std; void Copy(string * Source, string * Destination);//???? int main() { string Source = "Robile"; string Destination = "Lance"; Source.append(Destination); Copy(&Source , &Destination); } void Copy(string * Source, string * Destination) { cout << "Destination String Now is " << *Destination << "\n"; }
Not asking for complete code just tips on what to do and howto(Correction of code above) Thanks in advance -
Hi Can someone please help me with this. :( Given the following-> Write a function called Copy, witch takes two parameters of type string. The first par is your Source(string to be copied) second is your Dest string(target) this function need not return anything(NOT ALLOWED TO USE strcpy) I need to show how i would use this function(call) by writing code that copy one string into another. A deep copy should take place not Shallow. How can i implement the following in my function clear, erase, resize, append and index operator. How does the following piece of code look?
#include #include using namespace std; void Copy(string * Source, string * Destination);//???? int main() { string Source = "Robile"; string Destination = "Lance"; Source.append(Destination); Copy(&Source , &Destination); } void Copy(string * Source, string * Destination) { cout << "Destination String Now is " << *Destination << "\n"; }
Not asking for complete code just tips on what to do and howto(Correction of code above) Thanks in advance -
Hi Can someone please help me with this. :( Given the following-> Write a function called Copy, witch takes two parameters of type string. The first par is your Source(string to be copied) second is your Dest string(target) this function need not return anything(NOT ALLOWED TO USE strcpy) I need to show how i would use this function(call) by writing code that copy one string into another. A deep copy should take place not Shallow. How can i implement the following in my function clear, erase, resize, append and index operator. How does the following piece of code look?
#include #include using namespace std; void Copy(string * Source, string * Destination);//???? int main() { string Source = "Robile"; string Destination = "Lance"; Source.append(Destination); Copy(&Source , &Destination); } void Copy(string * Source, string * Destination) { cout << "Destination String Now is " << *Destination << "\n"; }
Not asking for complete code just tips on what to do and howto(Correction of code above) Thanks in advancefirstly how to write a function prototype that does a deep copy (not a copy of the values only). Secondly how would i write a member function from your perspective. What is the deference between operator=() and Copy()? The code above compiles but is it the write way to do it taking what i have stated in my thread in to mind?
-
firstly how to write a function prototype that does a deep copy (not a copy of the values only). Secondly how would i write a member function from your perspective. What is the deference between operator=() and Copy()? The code above compiles but is it the write way to do it taking what i have stated in my thread in to mind?
bhangie wrote: ...a function prototype that does a deep copy I've never seen the adjective "deep" used with "copy." What does it mean? bhangie wrote: What is the deference between operator=() and Copy()? Fundamentally, nothing. It's all a matter of how you want to use it. Which of these looks more natural:
Object a, b;
a.Copy(b);
// or
a = b;
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)