错误:无法通过'...'传递非平凡可复制类型的对象'class boost::filesystem::path'
error: cannot pass objects of non-trivially-copyable type 'class boost::filesystem::path' through '...'
错误:
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';
非常感谢!
- 平凡类型与非平凡类型的复制消除差异
- 简单可复制与可简单复制
- reinterpret_cast,只读访问,简单的可复制类型,会出什么问题?
- 对于参加可复制和可移动类的访问者来说,应该有多少过载?
- 可变参数宏:无法通过"..."传递非平凡可复制类型的对象
- 如何将 n 个连续元素插入到元素类型不可复制的 std::vector 中?
- 为什么 std::atomic<std::string> 会给出微不足道的可复制错误?
- 我可以隐式地创建一个琐碎的可复制类型吗
- 是std::memcpy在不同的可复制类型之间的未定义行为
- 为什么一对常量是微不足道的可复制的,而对不是?
- 防御性地应用 std::move 到平凡可复制的类型是否不可取
- 为什么 std::function 本身是可复制构造的类型?
- 错误:无法通过'...'传递非平凡可复制类型的对象'class boost::filesystem::path'
- 使用临时存储区复制普通的可复制类型:允许吗
- 非平凡可复制类型的值表示
- 类型 traits,用于检查参数包中的所有类型是否都是可复制构造的
- 交换包含非一般可复制类型的“std::aligned_storage”实例-未定义的行为
- 错误:无法通过`..`传递非普通可复制类型的对象
- 无法传递非普通可复制类型“const class mysqlpp::String”的对象
- 将std::memcpy用于非平凡可复制类型的对象