Code: Select all
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>
Mow, der versucht, Smart Zeiger zu verwenden, werde ich es so tun: < /p>
int Foo(const std::wstring &catalog, /*...*/)
{
std::unique_ptr cat = std::make_unique( catalog.length() + 2 );
// copy catalog to cat
// perform some work
}
Code: Select all
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>
und Ich nennen es mit < /p>
uc_to_str_cpy( cat, catalog );
< /code>
Jetzt ändert sich der Anruf in < /p>
uc_to_str_cpy( cat.get(), catalog );