Copying constructor making error

I'm doing an assignment which building a header file of a program. I'm facing an error which cannot copy the content of original vector
1
2
3
4
5
6
7
8
9
10
11
  template<class T>
Vector<T> & Vector<T>::operator=(const Vector<T> & v)
{
    //delete [] buffer;
    my_size = v.my_size;
    my_capacity = v.my_capacity;
    buffer = new T [my_size];
    for (int i = 0; i < my_size; i++)
       buffer[i] = v.buffer[i];
    return *this;
}

above is the function. regardless of the delete, it makes the same problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Vector<string> v3(2, "hello");
   assert(v3.size() == 2);
   assert(v3.capacity() == 2);
   assert(v3[0] == "hello");
   assert(v3[1] == "hello");

   v3.resize(1);
   assert(v3.size() == 1);
   assert(v3[0] == "hello");

   Vector<string> v4 = v3;
   assert(v4.size() == 1);
   assert(v4[0] == v3[0]); //This line occurs the problem.
   v3[0] = "test";
   assert(v4[0] != v3[0]);  
   assert(v4[0] == "hello"); //This line occurs problem as well. 

Above is the main function.

1
2
a.out: test.cpp:34: int main(): Assertion `v4[0] == v3[0]' failed.
Aborted (core dumped) 


Above is the result of running the program.

Thank you in advance!
You did not post relevant part: copy constructor. (and assigment operator is not used anywhere in your code)
Topic archived. No new replies allowed.