错误:无法通过'...'传递非平凡可复制类型的对象'class boost::filesystem::path'

error: cannot pass objects of non-trivially-copyable type 'class boost::filesystem::path' through '...'

本文关键字:类型 可复制 对象 path class filesystem boost 错误      更新时间:2023-10-16

错误:

init.cpp:在函数'bool appinit2()'中:

init.cpp:608:83:错误:无法传递非平淡无奇的类型的对象'class boost :: filesystem :: path'take'take'take'...'

printf("创建%s->%s n",sourcefile,backupfile);

init.cpp:608:83:错误:无法传递非平淡无奇的类型的对象'class boost :: filesystem :: path'take'take'take'...'

init.cpp:643:76:错误:无法将'boost :: filesystem :: path'to'const char*'for参数'2'转换为'int sprintf(char*,const char*,...)'

sprintf("删除旧备份:%s n",file.second);

make:*** [obj/init.o]错误1

filesystem::path backupDir = GetDataDir() / "backups";
if (!filesystem::exists(backupDir))
{
    // Always create backup folder to not confuse the operating system's file browser
    filesystem::create_directories(backupDir);
}
nWalletBackups = GetArg("-createwalletbackups", 10);
nWalletBackups = std::max(0, std::min(10, nWalletBackups));
if(nWalletBackups > 0)
{
    if (filesystem::exists(backupDir))
    {
        // Create backup of the wallet
        std::string dateTimeStr = DateTimeStrFormat(".%Y-%m-%d-%H.%M", GetTime());
        std::string backupPathStr = backupDir.string();
        backupPathStr += "/" + strWalletFileName;
        std::string sourcePathStr = GetDataDir().string();
        sourcePathStr += "/" + strWalletFileName;
        boost::filesystem::path sourceFile = sourcePathStr;
        boost::filesystem::path backupFile = backupPathStr + dateTimeStr;
        sourceFile.make_preferred();
        backupFile.make_preferred();
        try {
            boost::filesystem::copy_file(sourceFile, backupFile);
            printf("Creating backup of %s -> %sn", sourceFile, backupFile);
        } catch(boost::filesystem::filesystem_error &error) {
            printf("Failed to create backup %sn", error.what());
        }
        // Keep only the last 10 backups, including the new one of course
        typedef std::multimap<std::time_t, boost::filesystem::path> folder_set_t;
        folder_set_t folder_set;
        boost::filesystem::directory_iterator end_iter;
        boost::filesystem::path backupFolder = backupDir.string();
        backupFolder.make_preferred();
        // Build map of backup files for current(!) wallet sorted by last write time
        boost::filesystem::path currentFile;
        for (boost::filesystem::directory_iterator dir_iter(backupFolder); dir_iter != end_iter; ++dir_iter)
        {
            // Only check regular files
            if ( boost::filesystem::is_regular_file(dir_iter->status()))
            {
                currentFile = dir_iter->path().filename();
                // Only add the backups for the current wallet, e.g. wallet.dat.*
                if(currentFile.string().find(strWalletFileName) != string::npos)
                {
                    folder_set.insert(folder_set_t::value_type(boost::filesystem::last_write_time(dir_iter->path()),

*dir_iter)); } } } //通过备份文件向后循环并保留N最新的文件(1&lt; = n&lt; = 10) int counter = 0; BOOST_REVERSE_FOREACH(pairtype(const std :: time_t,boost :: filesystem :: path)文件,folder_set) { 计数器 ; 如果(counter> nwalletbackups) { //超过nwalletbackups备份:删除最古老的一个(s) 尝试 { boost :: filesystem :: remove(file.second); sprintf("旧备份删除:%s n",file.second); } catch(boost :: filesystem :: filesystem_error&amp; error){ sprintf("无法删除备份%s n",error.what.what()); } } } } }

朋友的 @πάνταῥεῖ答案解决了我的问题!

std::cout << "Creating backup of" << sourceFile << "->" << backupFile << 'n';
std::cout << "Old backup deleted:" << file.second << 'n';

非常感谢!