Let yourself design a string-like type that requires a constructor that accepts parameters of type char*
exercises in cPP primer 5th
vector[char]allocator
related codes
class MyString {
MyString();
MyString(char*);
allocator<char> alloc_char;
};
MyString::MyString ()
{
}
MyString::MyString (char* tc) {/ / pass a parameter of type char []. Class purpose: support a
//char[] string
int num = sizeof(tc); //
vector<char> trans(tc,tc+num); //allocator[]
//vector[]
//allocator<char> alloc_char; //
auto const p = alloc_char.allocate(num); //
auto q = uninitialized_copy(trans.begin(),trans.end(),p);
//auto q=p;
//q
/*
{ //
}*/
while (q != p) //q
alloc_char.destroy(--q);
alloc_char.deallocate(p, num);
//auto tc_begin = tc.begin();
}
int main ()
{
NULL;
return 0;
}
I had hoped to transfer the char* to the Allocator [char] successfully before proceeding with other processes.?
actual error message:
error C 4996 "std::uninitialized_copy::_Unchecked_iterators::_Deprecate": Call to" std::uninitialized_copy" with parameters that may be unsafe-this call relies on the caller to check that the passed values are correct. To disable this warning, use-D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual CPP "Checked Iterators" (Line) 53
error location code (in the header file < memory >):
template < class _ InIt,
class _FwdIt> inline
_FwdIt uninitialized_copy(_InIt _First, _InIt _Last,
_FwdIt _Dest)
{ // copy [_First, _Last) to raw [_Dest, ...)
_DEPRECATE_UNCHECKED(uninitialized_copy, _Dest);
_DEBUG_RANGE(_First, _Last);
const auto _UFirst = _Unchecked(_First);
const auto _ULast = _Unchecked(_Last);
const auto _UDest = _Unchecked_n(_Dest, _Idl_distance<_InIt>(_UFirst, _ULast));
return (_Rechecked(_Dest,
_Uninitialized_copy_unchecked(_UFirst, _ULast, _UDest, _Ptr_copy_cat(_UFirst, _UDest))));
}
my Xiaobai doesn"t quite understand. It should be the initialization problem of allocator. Replace that line with auto qroomp; and it will work properly.
how to initialize the correct one.