草庐IT

non-unique

全部标签

c++ - 通过 make_unique/make_shared 调用 initializer_list 构造函数

我正在尝试使用std::make_unique来实例化一个类,其构造函数将接收std::initializer_list。这是一个最小的案例:#include#include#include#includestructFoo{Foo(std::initializer_liststrings):strings(strings){}std::vectorstrings;};intmain(int,char**){autoptr=std::make_unique({"Hello","World"});return0;}您可以在Coliru上查看它没有建立:main.cpp:14:56:err

c++ - 通过 make_unique/make_shared 调用 initializer_list 构造函数

我正在尝试使用std::make_unique来实例化一个类,其构造函数将接收std::initializer_list。这是一个最小的案例:#include#include#include#includestructFoo{Foo(std::initializer_liststrings):strings(strings){}std::vectorstrings;};intmain(int,char**){autoptr=std::make_unique({"Hello","World"});return0;}您可以在Coliru上查看它没有建立:main.cpp:14:56:err

c++ - 错误 : non-aggregate type 'vector<int>' cannot be initialized with an initializer list

我是C++初学者,每次运行vectornums={2,5,3,7,1};它给了我错误:无法使用初始化列表初始化非排列类型vector。你能告诉我为什么吗?谢谢, 最佳答案 使用g++-std=c++11编译时。 关于c++-错误:non-aggregatetype'vector'cannotbeinitializedwithaninitializerlist,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c

c++ - 错误 : non-aggregate type 'vector<int>' cannot be initialized with an initializer list

我是C++初学者,每次运行vectornums={2,5,3,7,1};它给了我错误:无法使用初始化列表初始化非排列类型vector。你能告诉我为什么吗?谢谢, 最佳答案 使用g++-std=c++11编译时。 关于c++-错误:non-aggregatetype'vector'cannotbeinitializedwithaninitializerlist,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c

ruby-on-rails - FactoryBot 和 Faker - unique 不起作用

我正在使用FactoryBot和Faker进行测试,看起来Faker正在生成相同的名称:classProfile即使我使用独特的方法,我也收到错误ActiveRecord::RecordInvalid:Validationfailed:Nicknamehasalreadybeentaken`.有什么线索吗? 最佳答案 应该是:first_name{Faker::Name.unique.first_name}last_name{Faker::Name.unique.last_name}加载Faker::Name.unique.firs

c++ - 在 map 中使用自定义删除器存储 unique_ptr

为什么这不起作用?#include#includevoiddeleter(int*i){deletei;}std::map>m;voidfoo(int*i){m[0]=std::unique_ptr(i,&deleter);}查看无法理解的编译错误https://godbolt.org/z/Uhp9NO.Infileincludedfrom:1:Infileincludedfrom/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/map:61:Inf

c++ - 在 map 中使用自定义删除器存储 unique_ptr

为什么这不起作用?#include#includevoiddeleter(int*i){deletei;}std::map>m;voidfoo(int*i){m[0]=std::unique_ptr(i,&deleter);}查看无法理解的编译错误https://godbolt.org/z/Uhp9NO.Infileincludedfrom:1:Infileincludedfrom/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/map:61:Inf

ruby-on-rails - heroku 上的 Rails : after push, 得到 "PG::UniqueViolation: ERROR: duplicate key value violates unique constraint"

这已经被问过好几次了(here和here等等)。每次我将我的Rails应用程序推送到Heroku时(至少在过去的几个月里,我会说),我都必须使用熟悉的方法重置我的keyActiveRecord::Base.connection.tables.each{|t|ActiveRecord::Base.connection.reset_pk_sequence!(t)}咒语。否则,当我尝试创建新记录时,我会遇到这样的postgresql故障:PG::UniqueViolation:ERROR:duplicatekeyvalueviolatesuniqueconstraint"users_clie

c++ - GCC 错误 : explicit specialization in non-namespace scope

我正在尝试移植以下代码。我知道标准不允许在非名称范围范围内进行显式特化,我应该使用重载,但我只是找不到在这种特殊情况下应用这种技术的方法。classVarData{public:templateboolIsTypeOf(intindex)const{returnIsTypeOf_f::IsTypeOf(this,index);//noerror...}templateboolIsTypeOf(intindex)const//error:explicitspecializationinnon-namespacescope'classStateData'{returnfalse;}temp

c++ - GCC 错误 : explicit specialization in non-namespace scope

我正在尝试移植以下代码。我知道标准不允许在非名称范围范围内进行显式特化,我应该使用重载,但我只是找不到在这种特殊情况下应用这种技术的方法。classVarData{public:templateboolIsTypeOf(intindex)const{returnIsTypeOf_f::IsTypeOf(this,index);//noerror...}templateboolIsTypeOf(intindex)const//error:explicitspecializationinnon-namespacescope'classStateData'{returnfalse;}temp