use unintialized_copy where is initialized

Discussion in 'C++' started by Stanley Rice, Feb 18, 2012.

  1. Stanley Rice

    Stanley Rice Guest

    `the difference between *uninitialized_copy* function and *copy* is that the
    *uninitialized_copy* function could copy the object at the location where
    is uninitialized. For example:

    int ia[5] = {1, 2, 3, 4, 5};
    int n = sizeof ia / sizeof *ia;
    int *ib = (int *)malloc(n * sizeof *ia);
    uninitialized_copy(ia, ia + n, ib);

    My question is, what if I copy the initialized memory by calling the
    uninitialized_copy function. Instead of allocatiing the memory by calling
    malloc, I use new.
    int *ib = new int[n];
    uninitialized_copy(ia, ia + n, ib);

    I works too. But am i correct? If so, what's the difference between copy
    and uninitialized_copy?

    Stanley Rice, Feb 18, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.