View Single Post
Old 06-28-2005, 09:21 PM   #4 (permalink)
Aniviel833
Registered User
 
Join Date: Jun 2005
Posts: 26
Aniviel833 is on a distinguished road
Thanks for the explanation and the exercise. Here's what I've got:

Code:
#include <iostream>
#include <string>

namespace stacy
{

    //swap() swaps string1 and string2, then prints the new values.
    void swap(std::string string1, std::string string2)
        {
                std::string holder = "This will temporarily hold a string for me.";
        
                holder = string1;
                string1 = string2;
                string2 = holder;
                
                std::cout << "String 1 is now '" << string1 << "' and string 2 is '" << string2 << "'.";
        }

}



int main()
{
    stacy::swap("one", "two");
    std::cin.get();
}

This works fine, but I'm wondering about something: A while back, someone (who was doing Java; I don't know if this still applies...) was telling me that assigning an object to another (holder = string1) can cause problems because one object has two labels(?) At the end of swap(), holder and string2 are the same. Do I need to/should I do something about this?
Aniviel833 is offline   Reply With Quote