草庐IT

create_pointer_down

全部标签

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++ 使用 getline() 打印 : pointer being freed was not allocated in XCode

我正在尝试使用std:getline()但出现了一个奇怪的运行时错误:malloc:*errorforobject0x10000a720:pointerbeingfreedwasnotallocated*setabreakpointinmalloc_error_breaktodebug这是产生此错误的代码://main.cpp#include#includeintmain(intargc,char*constargv[]){std::istringstreammy_str("demostringwithspaces");std::stringword;while(std::getlin

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++ - 无法编译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++ - <type_traits> 的 is_function_pointer<>

中有这些:is_pointeris_functionis_member_function_pointer但不是这个:is_function_pointer为什么会这样? 最佳答案 [meta.unary.cat]中的特征旨在将每种类型归为一个类别。是void、integral、pointer等等。在这个层面上,pointer-to-function和pointer-to-int没有区别。并注意指向成员的指针不是指针。只不过是英文的谐音而已。它的目的是每个类型都返回true到[meta.unary.cat]中的一个特征。在这种分类中,

c++ - 使用 std::dynamic_pointer_cast 向上转换 std::shared_ptr

我开始在C++0X/11中使用智能指针,但遇到了一个特殊情况。我想使用shared_ptr向上转换一个对象的实例。Extend类继承自Base类,其中Base类具有虚拟析构函数以使其具有多态性(否则dynamic_pointer_cast会提示非多态类转换)。如果因此:std::shared_ptrobj=std::make_shared();然后我做:obj=std::dynamic_pointer_cast(obj);安全吗?其他指向该对象的指针会怎样?是否只有obj将其视为Extend,而其他共享指针仍将其视为Base?向上转换同一实例是否安全,还是我应该做其他事情?编辑:感谢您

c++ - 如果为 false,则 std::is_member_function_pointer 不编译

我在寻找什么:我有一个模板化类,如果该类具有所需的函数,我想调用一个函数,例如:templatedo_something(){ifconstexpr(std::is_member_function_pointer::value){this->_t->x();//_tistypeofT*}}会发生什么:如果T没有带来函数,编译器就不会编译。小例子:#include#includeclassFoo{public:voidx(){}};classBar{};intmain(){std::cout::value::value编译器说:is_member_function_pointer.cpp

c++ - 带有 const 指针的 boost::dynamic_pointer_cast 不起作用?

假设我有两个类,A和B,其中B是A的子类。我还有以下功能:voidfoo(boost::shared_ptra){boost::shared_ptrb=boost::dynamic_pointer_cast(a);//Error!}用gcc编译会出现以下错误:C:\Boost\include/boost/smart_ptr/shared_ptr.hpp:Inconstructor'boost::shared_ptr>::shared_ptr(constboost::shared_ptr&,boost::detail::dynamic_cast_tag)[withY=constA,T=c

C++ 对象 : When should I use pointer or reference

我可以使用一个对象作为指向它的指针,或者它的引用。我知道不同之处在于必须手动删除指针,而引用会一直保留到超出范围为止。我应该什么时候使用它们?实际区别是什么?这两个问题都没有回答我的疑惑:Pointervs.ReferenceC++differencebetweenreference,objectsandpointers 最佳答案 引用基本上是一个有限制的指针(必须在创建时绑定(bind),不能反弹/为空)。如果您的代码使用这些限制是有意义的,那么使用引用而不是指针允许编译器警告您意外违反它们。它很像const限定符:没有它语言也可

解决npm报错Error:EEXIST: file already exists, mkdir “文件路径“,yarn create vite-app 报文件名、目录名或卷标语法不正确

解决npm报错Error:EEXIST:filealreadyexists,mkdir"文件路径",yarncreatevite-app报文件名、目录名或卷标语法不正确第一个问题出现原因解决办法第二个问题出现原因解决引用文章第一个问题出现原因我这里出现错误是因为在配置npm命令目录与npm全局安装位置时目录创建失败,但是在执行yarnconfigsetglobal-folder与yarnconfigsetcache-folder命令之后在本地的".yarnrc"文件中"global-folder"属性被写入,之后会卡在Error:EEXIST:filealreadyexists,mkdir"文