草庐IT

make_member_delegate

全部标签

c++ - boost:初始化共享指针重置与 make_shared

除了生成代码的大小之外,使用reset()初始化函数make_shared()上的共享指针有什么区别?案例1使用reset()boost::shared_ptrpA;pA.reset(newA());案例2使用make_shared()boost::shared_ptrpA;pA=boost::make_shared();一般来说,使用reset而不是make_shared来减小可执行文件的大小是否是一个好习惯? 最佳答案 reset(newT(...))分配一个堆block,构造对象,为引用计数器分配一个新的堆block并初始化引

C++: 奇怪的 "Request for member X of Y which is of non-class type Z"

以下程序,用g++4.6编译,产生错误requestformember‘y’in‘a2’,whichisofnon-classtype‘A(B)’最后一行:#includetemplateclassA{public:Ty;A(Tx):y(x){}};classB{public:intu;B(intv):u(v){}};intmain(){intv=10;Bb1(v);//worksAa1(b1);//doesnotwork(theerroriswhena2isused)Aa2(B(v));//works//Aa2((B(v)));std::cout从代码中包含的工作变体可以看出,在A的

C++ STL make_heap 和 pop_heap 不工作

我需要使用堆,所以我搜索了STL,但它似乎不起作用,我写了一些代码来解释我的意思:#include#include#include#includestructdata{intindice;inttamanho;};boolcomparator2(constdata*a,constdata*b){return(a->tamanhotamanho);}intmain(){std::vectormesas;datax1,x2,x3,x4,x5;x1.indice=1;x1.tamanho=3;x2.indice=2;x2.tamanho=5;x3.indice=3;x3.tamanho=2;

C++ 结构 : more members, 成员访问时间慢得多?

我有一个结构链表。假设我将x百万个节点插入到链表中,然后我遍历所有节点以找到给定值。奇怪的是(至少对我而言),如果我有这样的结构:structnode{inta;node*nxt;};然后我可以遍历列表并检查a的值,这比我在结构中有另一个成员时快十倍,如下所示:structnode_complex{inta;stringb;node_complex*nxt;};我也用C风格的字符串(字符数组)尝试过,结果是一样的:只是因为我有另一个成员(字符串),整个迭代(+值检查)慢了10倍,即使我从来没有碰过那个成员!现在,我不知道结构的内部是如何工作的,但看起来要付出高昂的代价......有什么

c++ - 解决链接器错误 : undefined reference to static class members

我的代码是Arduinoish。我打开了详细编译,这样我就可以验证所有.o文件确实正确地传递给了链接器,并且它们是(下面的链接器命令)。这让我相信这是某种语法错误。谷歌搜索错误“undefinedreferencetoinfunction”会产生很多结果,答案包括“像这样将foo.o添加到您的链接器命令”等。我希望解决方案就像缺少点或->某处一样简单。我在一个文件中收到来自链接器的这一系列错误:SerialServoControl.cpp.o:Infunction`SerialServoControl::send(int,int)':SerialServoControl.cpp:31:

c++ - C2039 : Class is not a member of Namespace

Mage/Interface/Context.h#pragmaonce#include#include#include#includenamespaceMage{namespaceInterface{classContext{protected:RenderingContext*ctx;VertexBuffer*vbo;glm::mat4projection;Mage::Interface::Frame*uiParent;public:Context(RenderingContext*ctx);~Context();voidrender();Mage::Interface::Frame

基于 C++ 的 make 系统

是否有不使用DSL而实际使用C++作为构建语言的构建系统? 最佳答案 YoDawg,我听说你喜欢C++,所以我将C++添加到你的构建系统中,所以你必须先编译再编译。 关于基于C++的make系统,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5013827/

c++ - 为什么 std::sort() 比 std::make_heap() 快?

我有13721057我的元素std::vector.我需要对这个vector进行排序并获取前25个元素。我想,因为你可以在O(N)中构建一个堆弹出25个元素(每个元素都是O(logN))一定比在O(NlogN)中对整个vector排序更快.但是,当我对代码计时时:clock_ttStart=clock();sort(mostFrequent.begin(),mostFrequent.end(),greater());printf("Timetaken:%.2fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC);对比clock_ttStart=cl

c++ - C++ 错误 : class has no member named

我有这个问题MemoryBundleStorage.cpp:Inmemberfunction'virtualvoiddtn::storage::MemoryBundleStorage::store(constdtn::data::Bundle&)':MemoryBundleStorage.cpp:146:67:error:'constclassdtn::data::Bundle'hasnomembernamed'getClass'MemoryBundleStorage.cpp:150:19:error:'constclassdtn::data::Bundle'hasnomemberna

c++ - 没有 typedef 的运算符 member_function_pointer_type()?

是否可以在不使用typedef的情况下创建一个operatormember_function_pointer_type()(即通过内联指定成员函数指针的类型)?例如,在实现SafeBoolIdiom时:classFoo{typedefvoid(Foo::*bool_type)()const;public:operatorbool_type()const;};是否可以在声明运算符时直接写出bool_type的类型?如果是,怎么办? 最佳答案 这似乎是唯一不能在不使用typedef的情况下声明(类型转换)operator的情况。如果它是