草庐IT

main_template

全部标签

c++ - Curiously Recurring Template Pattern (CRTP) 是正确的解决方案吗?

场景考虑一个Logger类,它有一个为标准C++类型重载的成员函数write(),还有一些方便的函数模板,比如writeLine()内部调用write():classLogger{public:voidwrite(intx){...}voidwrite(doublex){...}...templatevoidwriteLine(Tx){write(x);...}...};进一步考虑一个子类FooLogger,它为特定于域的类型添加了额外的write()重载(我们称其中两个为FooType1和FooType2):classFooLogger:publicLogger{public:usi

c++ - 错误 : use of deleted function for overloaded template

我正在尝试模板特化,但无法确定为什么charconst*const无法在下面解析(尽管是有效类型)的原因。templateBfoo(A)=delete;templatevoidfoo(char*){}templatevoidfoo(charconst*const){}intmain(){{//typesOKcharconst*consta=nullptr;char*b=nullptr;}char*data;foo(data);//OKfoo(data);//ERRORreturn0;}错误error:useofdeletedfunction‘Bfoo(A)[withA=constcha

c++ - "run time templates"

我很确定答案是“你不能使用模板,你必须使用虚函数(动态多态性)”,但如果我走那条路,我似乎必须复制很多代码.这是设置:我目前有两个类,ColorImageSegmentation和GrayscaleImageSegmentation。他们做的事情本质上是一样的,但是有3个区别-它们对不同类型(ColorImage和GrayscaleImage)进行操作-一个参数,直方图的维度(3vs1)不同-PixelDifference函数根据图像类型不同如果我创建一个类templateclassImageSegmentation{};我会保持良好的状态。但是,我想让这个对象成为另一个类的成员:cl

c++ - main : linking fortran with C++的多重定义

我想编写一个C++程序,从中调用mvndst_()子例程http://www.math.wsu.edu/faculty/genz/software/fort77/mvndstpack.f在Linux上,如果我创建test.cc:extern"C"{intmvndst_(int*,double*,double*,int*,double*,int*,double*,double*,double*,double*,int*);};intmain(){return0;}并编译通过g++-c-otest.otest.ccgfortran-c-omvndstpack.omvndstpack.fgf

c++ - 了解 "template argument is invalid"错误消息

考虑代码:#include#includestructtest1{voidInvoke(){};};structtest2{templatevoidInvoke(){};};enumclassInvokableKind{NOT_INVOKABLE,INVOKABLE_FUNCTION,INVOKABLE_FUNCTION_TEMPLATE};templatestructget_invokable_kind{conststaticInvokableKindvalue=InvokableKind::NOT_INVOKABLE;};templatestructget_invokable_ki

c++ - 程序关闭时 Windows 是否会自动释放内存(不从 main 返回)?

这个问题在这里已经有了答案:Isitacceptablenottodeallocatememory(19个回答)关闭9年前。当程序关闭时,分配的新内存是否总是被释放?(即使由于错误/错误等或自定义关闭函数而意外关闭)?还是仅在从main返回时才释放内存?

c++ - 大括号和main方法中的返回值

这个问题在这里已经有了答案:Nocurlybracesaroundmain()--whydoesthiswork?(6个答案)关闭9年前。我读了这个code(BjarneStroustrup)。我很困惑...main函数体不在{}中,函数不返回值(作为int)。而且它有效……为什么?#include"std_lib_facilities.h"intmain()try{cout>val1>>op>>val2){//readnumberoperationnumberstringoper;doubleresult;switch(op){case'+':oper="sumof";result=

c++ - 该程序在 main() 上的 'return;' 之后需要很长时间才能关闭

这是我正在处理的代码:#include#includeusingnamespacestd;staticunsignedlongcollatzLength(unsignedlongn){staticstd::mapcollatzMap;intmapResult=collatzMap[n];if(mapResult!=0)returnmapResult;if(n==1){return1;}else{collatzMap[n]=1+collatzLength(n%2==0?n/2:3*n+1);returncollatzMap[n];}}intmain(){intmaxIndex=1;uns

python - python脚本能否知道Android环境下C++main函数的返回值

有几种调用C++可执行程序的方法。例如,我们可以使用defrun_exe_return_code(run_cmd):process=subprocess.Popen(run_cmd,stdout=subprocess.PIPE,shell=True)(output,err)=process.communicate()exit_code=process.wait()printoutputprinterrprintexit_codereturnexit_code处理一个C++可执行程序:run_exe_return_code('abc')而abc是由以下C++代码创建的:intmain()

c++ - template<> 用于成员枚举的显式特化

根据17.7.3[temp.expl.spec]第5段(N4659),...Membersofanexplicitlyspecializedclasstemplatearedefinedinthesamemannerasmembersofnormalclasses,andnotusingthetemplatesyntax.Thesameistruewhendefiningamemberofanexplicitlyspecializedmemberclass.However,templateisusedindefiningamemberofanexplicitlyspecializedm