草庐IT

void_type

全部标签

c++ - 编译器警告 : lambda return type cannot be deduced

考虑这个例子:#include#includeintmain(){std::stringstr="abcde4fghijk4l5mnopqrs6t8uvwxyz";std::stringstr2;std::remove_copy_if(str.begin(),str.end(),std::back_inserter(str2),[](char&c){if(std::isdigit(c))returntrue;//使用GCC4.6.1,这可以很好地编译并打印出预期的输出(字母表),但我收到一条警告说“只有当return语句是函数体中的唯一语句时,才能推导出lambda返回类型”.现在,我

c++ - VS2010 中的 "redefinition; different type modifier"

我正在尝试编译我在visualstudio中下载的一些代码。该代码适用于msvc6,我将其导入VS2010。该代码用于通过编译一个DLL来为labview提供ASIO支持。见here对于整个代码。构建时出现以下错误:“错误C2373:‘_pctype’:重新定义;不同的类型修饰符。”代码片段如下:unsignedshort_Ints[512];unsignedshort*_pctype=_Ints;如果有人要从我提供的链接中引用代码包,这是来自文件GenMonCIN.c 最佳答案 错误消息试图告诉您_pctype已在其他地方定义。它

c++ - 为什么 shared_ptr<void> 而不是 shared_ptr<HANDLE>

基于http://en.highscore.de/cpp/boost/smartpointers.html#smartpointers_shared_pointer#include#includeintmain(){boost::shared_ptrh(OpenProcess(PROCESS_SET_INFORMATION,FALSE,GetCurrentProcessId()),CloseHandle);SetPriorityClass(h.get(),HIGH_PRIORITY_CLASS);}问题:为什么h定义为boost::shared_ptr而不是boost::shared_

c++ - 无法将 ‘void* (Network::*)(void*)’ 转换为 ‘void* (*)(void*)’

我是一名初级C++程序员,我正在Linux机器上编程。我遇到了这个错误:cannotconvert‘void*(Network::*)(void*)’to‘void*(*)(void*)’forargument‘3’to‘intpthread_create(pthread_t*,constpthread_attr_t*,void*(*)(void*),void*)它来自这条线:pthread_create(&thread_id,0,&Network::SocketHandler,(void*)csock);我要调用的函数是:void*Network::SocketHandler(voi

c++ - 将 QUrl 传递给 QNetworkRequest 构造函数会导致 "non-class type"编译器错误

当我将QUrl传递给QNetworkRequest构造函数时,我从编译器中得到了奇怪的错误。更奇怪的是它只发生在特定的情况下,举个例子:#include#includeintmain(intargc,char*argv[]){QCoreApplicationa(argc,argv);QStringstr;QNetworkRequestreq(QUrl(str));req.setUrl(QUrl(str));//error:requestformember'setUrl'in'req',whichisofnon-classtype'QNetworkRequest()(QUrl)'QNet

c++ - cmake -D <变量> :<type>=<value> what does the parameter "-D" mean

我正在尝试使用cmake安装opencv。在opencv说明页面中,我找到以下示例:cd~/opencvmkdirreleasecdreleasecmake-DCMAKE_BUILD_TYPE=RELEASE-DCMAKE_INSTALL_PREFIX=/usr/local..据我了解,我应该在我创建的新目录中使用cmake生成Makefile,在这个例子中应该是~/opencv/release。但我不太明白最后一行。在cmake帮助中,我发现:cmake-D:==createacmakecacheentry这是什么意思?特别是这部分:":=",我不明白为什么这个例子给出了"CMAKE

c++ - (void)r++ 输入迭代器的要求

在24.2.3Inputiterators下,C++标准将输入迭代器的要求之一指定为表达式(void)r++等效于(void)++r.您也可以在cppreference看到这个.这是什么表情?这个要求有什么意义?为什么需要它?它看起来像一个C风格的强制转换,以取消r++或++r的结果,但我认为这不是它的真实面目。也就是说,稍微有点题外话,我似乎可以在类中定义一个void转换运算符。gcc和clang都编译它,但clang给出了警告:warning:conversionfunctionconverting'C'to'void'willneverbeused 最

c++ - 参数列表中的 void_t 有效但不作为返回类型

cppreference上有一个关于使用别名的例子。此示例失败,因为int没有成员foo:templateusingvoid_t=void;templatevoid_tf();f();//error,intdoesnothaveanestedtypefoo这很清楚,但是当我尝试将void_t部分放入参数列表时,它意外地编译了:templateusingvoid_t=void;templatevoidf(void_t);f();它可以在clang上编译,但不能在gcc上编译。这是错误吗? 最佳答案 templatestructvoid

c++ - 为什么 virtual void test()=00 有效但 virtual void test()=+0 和 virtual void test()=-0 无效?

我搜索了一些关于虚函数声明的帖子,相信=0在virtualvoidtest()=0;是固定句法所以virtualvoidtest()=NULL;virtualvoidtest()=false;virtualvoidtest()=1-1;virtualvoidtest()=0.0;和其他声明应该是无效的。但是我发现了virtualvoidtest()=00;virtualvoidtest()=000;virtualvoidtest()=0000;还能编译,为什么?还有,我觉得整数+0和-0其实和0一样(不知道对不对),就像00其实就是0一样,为什么virtualvoidtest()=+0

C++ : Different deduction of type auto between const int * and cont int &

这里是代码示例。a.intii=0;b.constintci=ii;c.autoe=&ci;-->eisconstint*d.auto&f=42;-->invalidinitializationofnon-constreferenceoftype‘int&’fromanrvalueoftype‘int’e.constauto&g=42-->ok观察:1.对于c)子句,自动推导类型const2.对于子句d),不会自动推导出类型const3.对于条款e),必须手动添加类型const才能使其工作。为什么子句c而不是d会自动推导类型const? 最佳答案