Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Copy an array created with new

Tags:

c++

copy

I have created two arrays List1 and List2 with new in C++. List1 is updated with data. I would like to copy List1 to List2. I tried using

std::copy(std::begin(List1), std::end(List1), std::begin(List2));

However, this does not work and gives the following error message:

error: ‘begin’ is not a member of ‘std’

Any possible suggestions for this error? Or alternative ways to copy in C++?

like image 380
SKPS Avatar asked Jan 26 '26 03:01

SKPS


1 Answers

"I have created two arrays List1 and List2 with new in C++"

The begin and end free functions won't work on a pointer.

Even if everything is correct, you may end up with no matching call to begin(T *&)

T is the type of your pointer.

Use std::vector or std::list other STL container or just simply static arrays to work with std::begin and std::end

like image 192
P0W Avatar answered Jan 28 '26 17:01

P0W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!