草庐IT

auto_created

全部标签

现代C++中的decltype(auto):理解与运用

在C++14及以后的版本中,decltype(auto)成为了编译器和开发者的得力助手。它主要用于在编译时推断表达式的类型,并保证推断出的类型在上下文中是有效的。decltype(auto)比传统的decltype更强大,因为它能够处理更为复杂和动态的类型。decltype(auto)的工作原理decltype(auto)会根据初始表达式的类型进行推断,并在必要时对推断出的类型进行调整,以确保类型安全和一致性。例如,如果初始表达式是一个数组,decltype(auto)将推断出数组的元素类型;如果初始表达式是一个函数,decltype(auto)将推断出函数的返回类型。decltype(aut

c++ - pthread_create() 是如何工作的?

鉴于以下情况:pthread_tthread;pthread_create(&thread,NULL,function,NULL);pthread_create对thread到底做了什么?thread在加入主线程并终止后会发生什么?如果在thread加入后执行此操作会发生什么情况:pthread_create(&thread,NULL,another_function,NULL); 最佳答案 Whatexactlydoespthread_createdotothread?thread是一个对象,它可以持有一个值来标识一个线程。如果p

c++ - 模板类中 auto 的不完整类使用

下面的代码格式是否正确?classB;templateclassA{Bdo_f()const;friendautof(Aconst&a){returna.do_f();}//#1};classB{};templateBA::do_f()const{returnB{};}intmain(){Aa;f(a);}如果我将#1​​中的auto更改为B,我会收到不完整的类型错误消息。为gcc/clang使用auto编译DemoB失败Demo 最佳答案 [dcl.fct.def.general]/2:Thetypeofaparameterort

c++ - 采访 : what is the difference between pthread and windows thread created by _beginthread(ex)?

我在一次C++开发人员职位面试中被问到这个问题,这个问题的答案是什么? 最佳答案 我会说:IfIwantedtocreateaportablecross-platformC++binary,I'dusepthreadsandusethepthreadimplementationforwindows.IfIwantedtocreateawindows-specificC++binary,I'dusebeginthreadandavoidthe3rdpartydependencyonthepthreadlibrary.如果他们真的想知道

c++ - `auto` 的 ref- 和 cv-stripping 属性。

我学会了以这种方式使用auto声明一个变量autovar=expr;基本上就像获取expr的类型并从中剥离&/&&-references和所有顶级常量和volatile。这是否意味着上面的行完全等同于下面的行?std::remove_cv::type>::typevar=expr; 最佳答案 不,那不是真的。autovar=expr;更像是传递expr按值(value)。intx[1];autoy=x;这使得y一个int*.主要是autox=expr;表现得像模板类型推导:templatevoidf(T);intx[1];f(x);

c++ - C++1 7's deduced ` auto` 非类型 `template` 参数是否可以使用显式非类型参数模式匹配模板?

考虑这个例子(alsoavailableonwandbox):templateclass>voidtest(){}templatestructX{};正在尝试实例化test()在clang++4.0(trunk)导致编译错误:error:nomatchingfunctionforcallto'test'test();^~~~~~~note:candidatetemplateignored:invalidexplicitly-specifiedargumentfor1sttemplateparametervoidtest(){}我最初的假设/直觉是test可用于匹配任何template具

c++ - 无法编译QT Create Quick Application项目

我是QTCreator的新手,我已经安装了带有MinGW4.9.232位的QTCreator5.6.2。我在编译快速应用程序项目时遇到问题,因为它总是显示此错误消息:Couldnotcreatedirectory"C:\Users\Hello\Documents\Errorin"Util.asciify("build-untitled-Desktop_Qt_5_6_2_MinGW_32bit-Debug")":TypeError:Property'asciify'ofobjectCore::Internal::UtilsJsExtension(0xb05718)isnotafuncti

c++ - 什么是auto_ptr_ref,它实现了什么以及如何实现的

auto_ptr_ref文档here说这个这是一个工具类,允许进行某些转换,这些转换允许将auto_ptr对象传递给函数并从函数返回。有人可以解释一下auto_ptr_ref如何帮助实现这一目标。我只想了解auto_ptr类及其内部结构 最佳答案 这有点令人困惑。基本上,auto_ptr_ref存在是因为auto_ptr拷贝构造函数并不是标准意义上的拷贝构造函数。复制构造函数通常有一个如下所示的签名:X(constX&b);auto_ptr复制构造函数的签名如下所示:X(X&b)这是因为auto_ptr需要修改从中复制的对象,以便将

c++ - 对 boost::timer::auto_cpu_timer 的 undefined reference

我尝试使用g++4.4在Debian的远程服务器上使用boost库编译小型.cpp文件。为此,我使用Netbeans。我的家用机器在Windows7上。解决了一些链接下一个代码的问题后#include#include#includeintmain(){boost::timer::auto_cpu_timerac;//line5return0;//line6}产生2个错误:第5行:对boost::timer::auto_cpu_timer::auto_cpu_timer(short)'的undefinedreference第6行:对boost::timer::auto_cpu_timer

c++ - 使用 'auto' 和 std::minmax 观察奇怪的行为

我在SUSEEnterpriseLinux11上使用GCC4.7.2和Boost1.58.0。我有以下代码片段,它基本上通过多边形列表来计算它们的长度/宽度。在std::minmax函数中使用“auto”关键字时,我看到了奇怪的输出。为了进行比较,我还声明了第二个变量,其中明确声明了类型(即dim与dim1)。namespacegtl=boost::polygon;typedefgtl::polygon_90_dataLayoutPolygon;typedefgtl::rectangle_dataLayoutRectangle;staticLayoutFeatureVeccalc_st