草庐IT

make_more_helpers

全部标签

c++ - std::make_pair 类型推导

我遇到了一些奇怪的事情,我想得到解释。以下代码片段提供了一个简单的类模板type和两个operators:一个用于type的特化和一个std::pair的type特化。#include#includetemplateclasstype{public:Tvalue_;};templatestd::basic_ostream&operator&os,typeconst&a){returnosstd::basic_ostream&operator&os,std::pairconst&a){returnosintmain(){usingfloat_type=type;float_typecon

c++ - 将 make_unique<X> 分配给 shared_ptr<X>

我(错误地)在我的程序中进行了以下分配:std::shared_ptrm_program;//inclassm_program=std::make_unique();//inmethod当我发现它时,我首先想知道为什么它甚至可以编译。事实证明,shared_ptr对unique_ptr对象有一个特殊的移动赋值运算符。我的问题是,这样做是否总是安全的,或者它有任何影响吗?(对于代码执行来说是安全的;对于代码审查来说显然是不安全的……) 最佳答案 从某种意义上说,这样做是“安全的”,您不会遇到任何重复删除或其他问题。这样做是不行的,因为

c++ - Make 始终针对目标 "all"运行,即使没有任何更新

我有这些文件测试.cpp点.h点.cpp三角形.h三角形.cpp我想要一个makefile,它允许我通过发出makePoint或分别构建每个类Point和Trianglecode>makeTriangle在需要时(头文件或源文件已更改)。makeall应该编译所有内容并在需要时构建输出程序Test。这是我到目前为止的想法:CXX=g++CXXFLAGS=-std=c++11-Wall-pedanticOBJS=Test.oPoint.oTriangle.oall:$(OBJS)$(CXX)$(CXXFLAGS)$(OBJS)-oTestPoint.o:Point.cppPoint.h$

C++ typelist make 子列表

假设我有一个类型templatestructtypelist{};我需要从此列表中获取子列表:templatestructsublist{usingtype=?;//};例如sublist::type==typelist当start=0我有一个有效的tail实现:templatestructtypelist{};templatestructtail{usingtype=typenametail::type;};templatestructtail{usingtype=typelist;};usingT=tail::type;#include#includeintmain(){::pri

c++ - 'more than one instance of overloaded function "sqrt“匹配参数列表”怎么办?

我的代码在for循环中出错,for(j=3;j:morethanoneinstanceofoverloadedfunction"sqrt"matchestheargumentlist.我该如何解决?#include//determineifnumberisprimeboolisPrime(longn){intj,num=0;{if(num 最佳答案 尝试:for(j=3;j(num));j+=2)发生的事情是包含3个不同的definitionsofsqrt并且编译器不知道您要使用哪个。

c++ - 为什么 boost filter_iterator 有奇怪的 make_filter_iterator 函数?

在经历了一些痛苦之后,我设法拼凑了这个boostfilter_iterator的最小示例usingnamespacestd;std::functionstlfunc=[](uint32_tn){returnn%3==0;};intmain(){vectornumbers{11,22,33,44,55,66,77,3,6,9};autostart=boost::make_filter_iterator(stlfunc,numbers.begin(),numbers.end());autoend=boost::make_filter_iterator(stlfunc,numbers.end

c++ - 作业 : Making an array using pointers

我正在解决作业问题。我和其他一些学生非常确定我们的老师说错了,但也许不是。我已经检查了这里的一些问题,但无法真正找到使用指针创建本质上是数组的方法。说明如下。重写以下程序以使用指针而不是数组:代码是这样的intmain(){intsalary[20];inti;for(i=0;i>salary[i];}for(i=0;i我的解决方案是这样的:intmain(){int*salary_pointer=newint;for(inti=0;i>*(salary_pointer+i);}for(inti=0;i它一直在salarynumber13左右标记段错误我的主要目的(因为我几乎可以肯定我

c++ - gvim :make command does not work

我在Unix环境下,使用C++工作。我从一个目录中打开gvim,该目录中存在一个名为“Makefile”的生成文件。当我尝试在vim中使用":make"时,我得到:外壳返回2(1of1):make:***未指定目标且未找到makefile。停止。 最佳答案 你有autochdir吗启用?那可能会更改到另一个目录。检查:pwd以查看当前目录是否是您所期望的。尝试运行:!ls以查看Makefile是否存在。 关于c++-gvim:makecommanddoesnotwork,我们在Stack

c++ - 警告 C4114 : same type qualifier used more than once

在将VC++6.0开发的代码迁移到VisualStudio2008时,我在代码的下面一行中收到此警告。constintconstCImportContext::PACKETSIZE=4096;我知道如何修复指针staticconstintconst*PACKETSIZE;//C4114staticconstint*constPACKETSIZE;//Correct但我的问题是如何解决这个警告,如果它像下面的警告(没有指针),staticconstintconstPACKETSIZE; 最佳答案 指针有两种不同的const限定符是有意

c++ - 将 make_shared 与可变参数模板绑定(bind)

我正在尝试编写以下工厂类,但找不到正确的语法:templateclassFactory{public:Factory(TArgs...args){creator_=std::bind(&std::make_shared,args...);//^^^someerroraroundhere}std::shared_ptrCreate()const{returncreator_();}private:std::function()>creator_;};这就是我使用工厂的方式:classFoo{public:Foo(boolvalue){}};classBar{public:Bar(cons