what is wrong with my copy function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yaoc1987
    New Member
    • Mar 2010
    • 8

    what is wrong with my copy function?

    hello everyone

    im writing a program for "sequence class with dynamic arrays"
    every time i compile it gives me this error:

    1>c:\documents and settings\yue jiang\desktop\s pring 2010\csc 212\hw\hw #3\sequence2.cx x(30) : error C3861: 'copy': identifier not found
    1>c:\documents and settings\yue jiang\desktop\s pring 2010\csc 212\hw\hw #3\sequence2.cx x(53) : error C3861: 'copy': identifier not found
    1>c:\documents and settings\yue jiang\desktop\s pring 2010\csc 212\hw\hw #3\sequence2.cx x(141) : error C3861: 'copy': identifier not found
    i believe all 3 is the same
    to use copy i know i have to include algorithm

    here is my copy function codes used in this program:

    Code:
    sequence::sequence(const sequence& source)
          {//copy constructor
          
             data= new value_type[source.capacity];
             capacity = source.capacity;
             used = source.used;
             current_index = source.current_index;
             copy(source.data, source.data + used, data);
          
          }
    
    void sequence::resize(size_type new_capacity)
          {//changes capacity accordingly
          
             value_type* larger_array;
          
             if(new_capacity == capacity)
                return;
          
             if(new_capacity < used)
                new_capacity = used;
          
             larger_array = new value_type[new_capacity];
             copy(data, data + used, larger_array);
             delete [] data;
             data = larger_array;
             capacity = new_capacity;
          
          }
    
    void sequence::operator = (const sequence& source)
          {//modify =
          
             value_type* new_data;
          
             if(this == &source)
                return;
          
             if(capacity != source.capacity)
             {
                new_data = new value_type[source.capacity];
                delete [] data;
                data = new_data;
                capacity = source.capacity;
             }
          
             used = source.used;
             current_index = source.current_index;
             copy(source.data, source.data+used, data);
          
          }
    ive look through the whole thing and everything seem correct to me
    anyone can help me out n spot my mistake...

    thanks in advance
    Last edited by Banfa; Mar 3 '10, 09:31 AM. Reason: Change quote tags to code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Do you include the algorithm header in your code?
    #include <algorithm>

    Do you enable the standard namespace?
    using namespace std;

    Comment

    • yaoc1987
      New Member
      • Mar 2010
      • 8

      #3
      definitely

      i included the <algorithm> and the others in the test file, header file, and implementation file but somehow i still get this error

      my brother told me it could be the parameters of the copy function but i checked already the parameters are correct

      sigh... hopefully my professor will grade according to the codes and not just whether the program works...

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Maybe you could post the .cxx file so we can see what you included.

        Comment

        Working...