草庐IT

TEMPLATE_DEBUG

全部标签

c++ - C++ 模板的部分特化 : template parameter not deducible

下面的代码工作正常:templateclassFib{};templateclassFib{};但是下面的代码显示错误为:Error:templateparametersnotdeducibleinpartialspecialization:templateclassFib{};templateclassFib{};你能解释一下这种行为的原因吗? 最佳答案 我相信您只是缺少部分特化的正确语法:templateclassFib{};templateclassFib{};模板上的第一个参数是类型,而第二个只是一个常量值。

c++ - template<class = enable_if_t<...>> 做什么?

我一直在阅读STL文件,以学习格式化代码的更好方法,并学习提高效率的技巧。我一直在阅读线程文件,但我无法弄清楚某些代码的作用。template,thread>::value>>explicitthread(_Fn&&_Fx,_Args&&..._Ax){//constructwith_Fx(_Ax...)...}std::enable_if_t是templateusingenable_if_t=typenameenable_if::type;templatestructenable_if{//typeis_Tyfor_Testusingtype=_Ty;};该代码在thread和str

c++ - Cryptic template 模板参数错误

我正在尝试创建一个从std::map或std::unordered_map获取键的函数。我可以使用简单的重载,但首先我想知道这段代码有什么问题。templateclassTContainer>std::vectorgetKeys(constTContainer&mMap){std::vectorresult;for(constauto&itr(std::begin(mMap));itr!=std::end(mMap);++itr)result.push_back(itr->first);returnresult;}当使用std::unordered_map调用它时,甚至手动指定所有模板

c++ - 嵌套类声明 : template vs non-template outer class

我有一个C++模板类,里面有一个嵌套类,比如:templateclassOuter_t{public:classInner;Inneri;};templateclassOuter_t::Inner{public:floatx;};intmain(){Outer_to_t;//3oranyarbitraryinto_t.i.x=1.0;return0;}编译没有任何问题。然而,一旦我声明了一个类似的非模板类,就像这样:classOuter_1{public:classInner;Inneri;};classOuter_1::Inner{public:floatx;};intmain(){

c++ - #ifdef _DEBUG 在主函数中

如果我在visualstudio2013上工作,main函数中的#ifdef_DEBUG是否有意义?如果是,它的用途是什么?int_tmain(intargc,_TCHAR*argv[]){#ifdef_DEBUG//creatingsomeobjects,usingfunctionsetc;#endif} 最佳答案 #ifdefDEBUG或#ifdef_DEBUG用于处理您用于调试目的的一些代码。如果添加#undef_DEBUG或在代码的最开头与此类似,编译器将跳过#ifdefDEBUG/*blabla*/#endif中包含的代码

c++ - 错误 : 'Failed to specialize function template' C2893 'std::invoke'

我正在VisualStudio2013中编写MFC程序,但我不断收到以下两个错误错误C2893无法特化函数模板'unknown-typestd::invoke(_Callable&&,_Types&&...)'和错误C2672“std::invoke”:找不到匹配的重载函数错误与文件xthread第238行有关我是c++/MFC的新手,我正在尝试编写一个将在后台运行到系统时间的函数。这是我使用的代码:voidtask1(ExperimentTab&dlg){while(true){CStringshowtime=CTime::GetCurrentTime().Format("%H:%M

c++ - va_list 还在 C++ 中使用吗?还是鼓励使用 template<typename...T>?

在C中,定义可变长度参数的唯一方法是使用省略号声明其原型(prototype)并使用va_list、va_start、va_arg,va_end来提取它们。就像printf系列和scanf系列一样。在C++11中,引入了如下新方法。templatevoidfunc(Targ,MoreT...args){//Dosomestufffunc(args);}每种方法的优点和缺点是什么?在C++中是不鼓励使用还是鼓励使用它们中的任何一个? 最佳答案 在C++中强烈不鼓励使用C风格的可变参数函数。风格各不相同,但编写这些类型的函数会让您在某些

c++ - 如何在Visual Studio中跳过Debug Assertion Failed直接break

我正在使用一些C++,我的代码中有一个拼写错误导致了这个问题。将来,我宁愿VisualStudio在直接从VisualStudio2017(社区版)以DEBUGMODE运行时直接中断错误代码,使用实际表达式,而不是向我显示这个烦人的提示。某处有这个设置吗? 最佳答案 Isthereasettingforthissomewhere?您可以通过settingreportmode以编程方式完成它:_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_DEBUG);所需的header是.

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