The problem of uninitialized_copy function error in C++primer 5

Source: Internet
Author: User

A problem with an error in a function in C++primer

This class is defined in the design of the Strvec class and defines a static variable alloc, which is used to allocate memory and construct elements

Class Strvec
{
Public
Strvec (): Elements (nullptr), First_free (nullptr), Cap (nullptr) {}
Strvec (initializer_list<string> Li);
Strvec (const strvec&);
strvec& operator= (const strvec&);
~strvec ();
void push_back (const string&); Copy elements
size_t size () const {return first_free-elements;}
size_t capacity () const {return cap-elements;}
String *begin () const{return elements;}
String *end () const {return first_free;}
void Reserve (size_t n);
void Resize (size_t n);
void Resize (size_t n, string str);
Private
Static Allocator<string> Alloc; static members, assigning

pair<string*, string*> alloc_n_copy (const string*, const string*); allocating memory, copying elements

At the time of implementing the function Alloc_n_copy

Pair<string *, string*> strvec::alloc_n_copy (const string *b, const string *e)
{
Auto Data =alloc.allocate (e-b);
return{data,uninitialized_copy (B,e,data)};
}

An unsafe warning is generated when the Uinitialized_copy function is called:

Error C4996 ' std::uninitialized_copy::_unchecked_iterators::_deprecate ': Call to ' std::uninitialized_copy ' with Parameters that is Unsafe-this call relies on the caller to check that the passed values is correct. To disable this warning, use-d_scl_secure_no_warnings. See documentation "On" use Visual C + + ' Checked iterators '

Calls to parameters may be unsafe, and the function's functions need to be called to ensure that the value of the iterator is correct. The program will error.

Remove the static declaration, plus the macro command # define _SCL_SECURE_NO_WARNINGS (. cpp file) to remove this warning

The problem of uninitialized_copy function error in C++primer 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.