草庐IT

copy-initialization

全部标签

c++ - 为什么 g++5 在自动类型推导中推导对象而不是 initializer_list

我最近发现了这段代码:structFoo{};intmain(){Fooa;//clang++deducesstd::initializer_list//g++5.1deducesFooautob{a};a=b;}它在g++5.1中编译良好,但在clang++中失败(同时使用-std=c++11和-std=c++14,结果相同)。原因是clang++deducesthetypeofbasstd::initializer_list,而g++5.1deducesasFoo.AFAIK,类型确实应该是(确实违反直觉)std::initializer_list这里。为什么g++5将类型推断为F

Hadoop:DataNode启动失败:Initialization failed for Block pool

一、问题发现​在启动Hadoop集群后,发现原本应该是启动三台机子的数据节点,结果只有一台node2成功启动,另外两台(node1、node3)并没有启动,如下两图所示:问题描述:​确认配置信息没问题后,查看Hadoop下hdfs目录中的DataNode日志(配置文件中指定,比如笔者安装Hadoop所在路径为/export/server/hadoop/logs/hdfs),DataNode的日志文件为:cat该文件发现:ERRORorg.apache.hadoop.hdfs.server.datanode.DataNode:InitializationfailedforBlockpoolreg

c++ - 为什么复制初始化是这样的?为什么需要复制构造函数?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:What’sthemotivationbehindhavingcopyanddirectinitializationbehavedifferently?通过复制初始化,我的意思是这样的:structMyStruct{MyStruct(int){}MyStruct(constMyStruct&){}};MyStructs=5;//needs*both*theintandcopyconstructor尽管使用C++编程多年,但我从未意识到上述代码需要复制构造函数(感谢jogojapan)。临时文件总是被省略,因此

c++ - clang 中的别名 std::initializer_list

我想使用std::initializer_list的别名来代替它本身:#includetemplateusingInitializerList=std::initializer_list;//note:candidatetemplateignored:couldn'tinfertemplateargument'T'templatevoidf(InitializerListlist){}intmain(){//error:nomatchingfunctionforcallto'f'f({1,2,3,4,5});}该代码使用gcc&cl没问题。但是,使用clang我得到一个错误::11:3

c++ - 意外的非常量 std::initializer_list

我正在尝试使用索引技巧来查看我可以去哪里并遇到一个奇怪的错误......首先,普通的不那么旧的索引:templatestructindices{};templatestructmake_indices:make_indices{};templatestructmake_indices:indices{};我创建了一个派生自std::initializer_list的编译时数组类,并使其可索引(假设N3471被您的编译器支持。它将在下一个标准中出现).在这里:templatestructarray:publicstd::initializer_list{constexprarray(st

c++ - 为什么 std::copy(从 istream 到 ostream)会引发 ios::failure 异常?

以下代码应将数据从wifstream复制到wcout。复制内容后,程序抛出ios::failure异常。#include#include#include#include#include#include#includeintmain(void){std::locale::global(std::locale(""));std::wifstreamis;is.exceptions(std::ios::failbit|std::ios::badbit);is.open("test.ts",std::ios::binary);is>>std::noskipws;std::istream_ite

c++ - 是否为 initializer_list 提供一个私有(private)构造函数?

此标准草案显示了initializer_list的概要.它没有私有(private)构造函数。但是我看过的两个标准库实现,libstdc++和libc++,都提供私有(private)构造函数://Thecompilercancallaprivateconstructor.constexprinitializer_list(const_iterator__a,size_type__l):_M_array(__a),_M_len(__l){}_LIBCPP_ALWAYS_INLINE_LIBCPP_CONSTEXPR_AFTER_CXX11initializer_list(const_E

c++ - std::copy_n 是否适用于重叠范围?

我正在查看N348525.3.1[alg.copy]中的C++标准,它定义了4种算法:复制copy_backwardcopy_ifcopy_n在copy的描述中,有这个注释25.3.1[alg.copy]/3:Requires:resultshallnotbeintherange[first,last)也就是说,当范围重叠时,copy并不总是正确工作(类似于memcpy)。copy_backward和copy_if有相似的语言禁止重叠范围(分别为25.3.1[alg.copy]/14和25.3.1[alg.copy]/8).但是copy_n没有这样的禁止,也没有copy_n_backw

c++ - 通过不明确的转换运算符进行引用绑定(bind)

#includeusingnamespacestd;structCL2{CL2(){}CL2(constCL2&){}};CL2cl2;structCL1{CL1(){}operatorCL2&(){coutclang和gcc都给出了模糊的转换运算符,但VisualStudio编译正常并打印“operatorconstCL2&”。怎样才符合标准?据我所知,将CL1转换为constCL2&是在复制初始化上下文中(作为cl2对象直接初始化的一部分)。我看过n4296草稿,[over.match.copy]:Assumingthat“cv1T”isthetypeoftheobjectbein

idea使用Spring Initializer创建springboot项目的坑【保姆级教学】

项目场景:提示:这里先简述项目创建后遇到的问题和解决方案:idea使用SpringInitializer创建springboot项目后,有以下问题:①右键没有Run②右键New新建文件发现无JavaClass选项然后解决掉①②问题后出现新的问题:③@SpringBootApplication注解爆红找不到引用④pom依赖能下载但是加载不到本地项目创建和解决方案提示:下面开始逐步演示创建过程遇到的问题和解决方案:①-File——>New——>Project②-选择默认Default,然后Next③-Type选择默认Maven,然后Next④-勾选上Web模板,然后Next⑤-选择好项目的位置,点