Thread: overloading the assignment operator

  1. #1
    Unregistered36
    Guest

    overloading the assignment operator

    I am trying to overload the assignment operator to copy two linked lists (List1 = newList). and i want the data members of the arguement and everythin to which the data members point copied..


    so i guess in my template(ItemType)/class(List) i should have a member function like this:

    void operator=(List<ItemType>);

    and in its implementatoin sumthin like this:

    template<class ItemType>
    void Stack<ItemType>:perator=(List<ItemType> newList)
    {
    //now im just havin trouble as to fillin in the body
    }

    where do i go from here?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    1. Check for self-assignment. If this is the case exit.

    2. Iterate through the old list deleting all existing nodes.

    3. Iterate through list to be copied creating new nodes as copies in the old list.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Assignment operator overloading
    By hsgw in forum C++ Programming
    Replies: 1
    Last Post: 01-20-2007, 06:44 PM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM