草庐IT

dispatch_get_current_queue

全部标签

c++ - "gets() was not declared in this scope"错误

这个问题在这里已经有了答案:whyg++shows"gets()"notdeclared,evenafterincluding(3个答案)关闭2年前。使用以下代码,我得到“gets()未在此范围内声明”错误:#include#includeusingnamespacestd;intmain(){//stringstr[]={"Iamaboy"};stringstr[20];`gets(str);cout

c++ - 为什么调用 `int* Get()` 而不是 `const int& Get()` ?

我有一个B类,它有两个方法,一个返回指向成员变量的指针,另一个返回对该变量的常量引用。我尝试调用这些方法。在调用期间,我将返回值存储到相应的返回类型。我期望适当的返回类型最终会调用适当的方法,但我收到一个编译错误:error:invalidconversionfrom‘int*’to‘int’[-fpermissive]constint&refval2=b.Get();`Hereismycode:#includeclassB{public:int*Get(){return&x_;}constint&Get()const{returnx_;}private:intx_=0;};intma

c++ - std::get_time 没有解析日期

如果我尝试使用std::get_time在tm中设置日期什么也没有发生,但是输入流处于失败状态,这意味着解析错误已经发生了。下面的代码有什么问题?{//settingtimeworksstd::tmt{};std::istringstreamss("01:02:03");ss.imbue(std::locale("de_DE"));ss>>std::get_time(&t,"%H:%M:%S");std::cout>std::get_time(&t,"%d");std::cout输出:0SunJan001:02:0319001SunJan000:00:001900

c++ - thread::get_id (C++11) 是免费的吗?

我想测试调用我的一个类的不同函数的线程。我有一个关键时间线程,我不希望任何人调用一个可能调用new的函数,以便从该线程调用。但是,由于这2个函数是公共(public)的,我无法通过语言强制执行。我的想法是测试线程id。假设我可以确保初始化线程ID的调用在正确的线程中,我只需要在其他调用中调用thread::get_id()并与我保存的线程ID进行比较。问题是我也想在关键线程中测试这个ID,但我不能锁定那个线程。因此我的问题是:thread::get_id()是否没有锁定(最糟糕的执行时间是什么时候)? 最佳答案 标准不保证threa

c++ - std::current_exception 是否应该从类的析构函数中的 catch block 返回非空

我和我的同事认为我们在VisualC++2012和2013中发现了一个错误,但我们不确定。以下代码中对std::current_exception的调用是否应该返回一个非空的exception_ptr?似乎在我们尝试过的大多数其他编译器上:#include#include#includeclassA{public:~A(){try{throwstd::runtime_error("ohno");}catch(std::exception&){std::clog在VisualC++下运行时,我们得到“0”(假,这意味着返回的exception_ptr为空)。其他编译器,例如g++,打印“

c++ - 为什么这个自定义比较器在构造 std::priority_queue 时失败,而它适用于 std::sort?

比较器comp定义如下。它适用于std::sort,但无法在std::priority_queue的构造函数中编译。问题是什么?谢谢。#include#include#includeusingnamespacestd;boolcomp(inta,intb){returna>b;}intmain(){vectorvec={4,2,1,3};sort(vec.begin(),vec.end(),comp);//OKpriority_queueq1(less(),vec);//OKpriority_queueq2(comp,vec);//Failreturn0;}错误信息:error:nom

C++ 在 priority_queue 中使用 std::greater() 并排序

为什么这两种情况的文档说的是同一件事,但它们以相反的方式声明,一个使用greater而另一个使用greater().任何人都可以解释一下吗?文档priority_queuecpplibrary说那个compcanbeComparisonobjecttobeusedtoordertheheap.Thismaybeafunctionpointerorfunctionobjectpriority_queue,greater>minheap;//workspriority_queue,greater()>minheap;//whyfail?文档cpplibrarysort说的是同一件事,即co

使用一种按位 : I'll get duplicated values? 的 C++ 函数

这是我的C++函数,它使用一种按位:intgenkey(constunsignedchara,constcharb,constcharc){intval=0;unsignedchar*p=reinterpret_cast(&val);p[0]=a;char*q=reinterpret_cast(&val);q[1]=b;q[2]=c;returnval;}我用它来生成键(对象的唯一值)。可以传递给函数的值的范围是:对于a参数=>[0..255],对于b参数=>[0..127]和对于c参数=>[0..127].假设该函数只能使用相同的三个参数值调用一次。例如,只有一次调用的值为(10,0

C++ std::queue 不想 push()

这是一个简单的类和简单的测试函数:#include#includenamespace{usingnamespacestd;}classNameStream{queuestream;public:stringoperator*(){returnstream.front();}NameStream&operator++(int){stream.pop();return*this;}NameStream&operator++(){stream.pop();return*this;}NameStream&operator它落在NameStream&operator在队列的推送过程中,这是我的代

c++ - OpenMP Mac OSX Lion c++ 链接器错误 Undefined symbols for architecture x86_64 : "_omp_get_thread_num"

我在互联网上的任何地方都找不到这个问题。所以我的链接器错误是:Undefinedsymbolsforarchitecturex86_64:"_omp_get_thread_num()"这是我的代码:intnthreads;inttid;#pragmaompparallelprivate(tid){tid=omp_get_thread_num();if(tid==0){nthreads=omp_get_num_threads();printf("numberofthreads:%d\n",nthreads);}} 最佳答案 看起来你忘