class template and operator=()

This is a discussion on class template and operator=() within the C++ Programming forums, part of the General Programming Boards category; Hey all, I'm working on a general (hopefully very useful) list class template. At the moment I'm stuck with dev-cpp ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    class template and operator=()

    Hey all, I'm working on a general (hopefully very useful) list class template. At the moment I'm stuck with dev-cpp giving me weird errors about my operator=() function:
    Code:
    template<class item_t>
    mylist& mylist<item_t>::operator=(const mylist list2) {
      mylist list1;
      list1.length = list2.length;
      int i;
      delete [] list1.list;
      list1.list = new item_t[list2.length];
      for (i = 0; i < list1.length; ++i)
        list1.list[i] = list2.list[i];
      return list1;
    }
    I'm not real familiar with templates so this is probably something super basic and obvious, but any help would be greatly appreciated, thx.
    Last edited by ichijoji; 10-04-2003 at 09:08 PM.
    Illusion and reality become impartiality and confidence.

  2. #2
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    the problem isn't in the code u posted, its in the class declaration.

    Post the full code and we can help u more.

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  3. #3
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    Here's a zip with alla the stuff.
    Attached Files Attached Files
    Illusion and reality become impartiality and confidence.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    mylist<item_t>& mylist<item_t>::operator=(const mylist list2) {
    Try changing it to that...

    [edit]



    Code:
    mylist list1;
    did you want to make it mylist<item_t> list1?

    also you shouldnt include cpp files, include the h file in the cpp file instead...

    [/edit]

    Man I can't think straight tonight...
    Last edited by JaWiB; 10-04-2003 at 09:29 PM.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    also you shouldnt include cpp files, include the h file in the cpp file instead...
    I got a book that says to do it this way or else the linking won't go down like it should and the evidence seems to point in that direction. Is there something neither of us know?
    Illusion and reality become impartiality and confidence.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  3. Replies: 6
    Last Post: 12-06-2005, 08:23 AM
  4. Syntax problems with Class Template
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2004, 06:25 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21