草庐IT

special_case

全部标签

c++ - 如果 switch case 失败,我如何让 MSVC 发出警告或失败?

如果我的一个switch语句有一个不中断的情况,我想得到一个警告/错误。这可能吗?switch(i){case1:cout在goingnative2012session上讨论了类似的Clang功能,但我需要它用于MSVC2013http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Clang-Defending-C-from-Murphy-s-Million-Monkeys理想情况下,当两个连续的主体没有被中断分开时,我会想要一个警告,这样上面的例子就会失败,但这不会:switch(i){case1:cout

c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

下面是一个给出编译时错误的程序。这主要与D类中的Boo函数有关。我最终尝试使用多个线程来调用solve方法,但目前这对我来说似乎不太有效,无法做到这一点。错误是:1>d:\dummy\project1\trash.cpp(37):warningC4101:'d':unreferencedlocalvariable1>c:\programfiles(x86)\microsoftvisualstudio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240):errorC2672:'std::invoke':no

c++ - decltype((void)T{}) in template Partial Specialization 不推导?

templatestructTest{staticconstintvalue=0;};templatestructTest{staticconstintvalue=2;};templatestructTest{staticconstintvalue=1;};intmain(){cout::valuegcc/clang上的代码都出现错误:模棱两可,但是将decltype更改为void_t是可以的。为什么? 最佳答案 对我来说,这看起来像是一个编译器错误:你真的需要T{}的副作用吗??decltype((void)T{})的整体构造应该

c++ - CUDA 和模板 : specialization declaration needed?

我有一个模板化包装函数,它调用在.cu文件中定义的内核(__global__)template__global__voidcompute_kernel(T*input,T*output,n){Mm;//computestuffusingm};templatevoidcompute(T*input,T*output,intn){//...computeblocks,threads,etc.compute_kernel>>(input,output,n);//...};和一个头文件包含在只有声明的主机代码中templatevoidcompute(T*input,T*output,intn)

C++ 微软 : How to associate uuid/guid with template specialization

我想将uuid/guid与模板特化相关联。以下代码可用于将uuid与非模板接口(interface)(类、结构)相关联:__interface__declspec(uuid("CECA446F-2BE6-4AAC-A117-E395F27DF1F8"))ITest{virtualvoidTest()=0;};GUIDguid=__uuidof(ITest);//OK现在我有了一个模板化的界面template__interfaceITemplateTest{virtualvoidTest(Tt)=0;};我想做以下工作:GUIDtemplateGuid=__uuidof(ITemplat

c++ - gcc 与 clang : noexcept parsed in unused template specialization when static casting

我正在尝试将函数指针静态转换为特定函数重载,但似乎clang仍会解析(未使用的)模板特化的noexcept语句,从而生成编译器错误。如果未使用相应的函数重载,GCC似乎并不关心noexcept。templatevoidfun(T)noexcept(T(1)){}voidfun(int){}voidfun(int*){}intmain(){inta;fun(&a);//callingworksfinefun(a);static_cast(&fun);//staticcastingdoesn't}https://godbolt.org/z/ixpl3f这里是哪个编译器出错了?当将函数指针转

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++ - if-cases 泄漏中定义的变量? (也就是为什么这甚至可以编译?)

似乎在if语句中声明的变量会泄漏到以下语句?我复制粘贴了一些代码,令我惊讶的是它在不应该编译的时候编译了!我正要提交代码,幸运的是我在那之前发现了错误。下面是一个显示问题的工作(?)程序。以下代码片段调用一个不存在的对象上的函数:#includeclassA{public:virtual~A(){}};classB:publicA{public:voidfooB(){std::cout(a)){b->fooB();}elseif(C*c=dynamic_cast(a)){c->fooC();b->fooB();}return0;}它编译并且输出是这样的:fooCfooB这肯定是错误的。

c++ - "virtual base class in the case of multilevel inheritance"有意义吗

考虑以下显示多级继承的示例代码:案例1:这里类derived1是通过虚拟继承从类base派生的,类derived2是从类派生的直接类derived1。classbase{};classderived1:virtualpublicbase{};classderived2:publicderived1{};Case2:与Case1相同,只是不涉及虚拟继承classbase{};classderived1:publicbase//novirtualinheritance{};classderived2:publicderived1{};假设我在这两种情况下都创建了derived2类的对象。C

c++ - 哪些提升类型用于 switch-case 表达式比较?

以下程序在使用不同的编译器编译时打印“unknown”。为什么会这样?#include"stdio.h"constcharOPTION=(char)(unsignedchar)253;intmain(intargc,char*argv[]){unsignedcharc=253;switch(c){caseOPTION:printf("option\n");break;default:printf("unknown\n");break;}return0;}在查看C++标准(N36902013-05-05)时,我看到了switch的子句:6.4.2Theswitchstatement2Th