Я пытаюсь отказаться от старой привычки и начать использовать умные указатели. < /p>
Мой текущий код: < /p>
Код: Выделить всё
int Foo(const std::wstring &catalog, /*...*/)
{
SQLWCHAR *cat = new SQLWCHAR[catalog.length() + 2];
memset( cat, '\0', catalog.length() + 2 );
// copy the catalog name to cat
// perform some work
delete[] cat;
cat = nullptr;
}
< /code>
косикаint Foo(const std::wstring &catalog, /*...*/)
{
std::uniqie_ptr cat = std::make_unique( catalog.length() + 2 );
// copy catalog to cat
// perform some work
}
Код: Выделить всё
void uc_to_str_cpy(SQLWCHAR *dest, const std::wstring &src)
{
const wchar_t *temp = src.c_str();
while( *dest )
{
dest++;
}
while( *temp )
{
*dest = *temp;
dest++;
temp++;
}
*dest++ = '\0';
*dest = '\0';
}
< /code>
И я называю его с < /p>
uc_to_str_cpy( cat, catalog );
< /code>
Теперь вызов изменится на < /p>
uc_to_str_cpy( cat.get(), catalog );
tia !!
Подробнее здесь: https://stackoverflow.com/questions/797 ... ialization
Мобильная версия