草庐IT

间接性

全部标签

c++ - C++ vtables中的双重间接

我编写了这个非常简单的C++程序,我想知道为什么编译器将vtable布局为跨越两个指针取消引用。这是C++程序:classFoo{public:virtualvoidbar(){}};intmain(intargc,char*arv[]){Foofoo;Foo*foo_p(&foo);foo_p->bar();}现在,我可以查看编译器生成的程序集:$g++-ggdb-Wall-O0-Stest.cpp以下是相关部分:.loc190leaq-16(%rbp),%rax#puttheaddressof'foo'in%raxmovq%rax,%rdi#useitasthefirstargum

c++ - 交叉引用和循环依赖。 header 间接包含自身

可放置的.h#include"selectable.h"classplaceable:selectable{..};可选择的.h#include"game.h"classselectable{..};游戏.h#include"placeable.h"classgame{...classplaceable*holding;...};基本上placeable.h包含selectable.h,其中包含game.h,而game.h又包含placeable.h。我能想到的唯一解决方案是将placeable*放在一个新的header中,使其成为静态/全局的,然后将这个新header包含在game.

c++ - 为什么需要间接寻址

这个问题在这里已经有了答案:CreatingCmacrowith##and__LINE__(tokenconcatenationwithpositioningmacro)(3个答案)关闭6年前。考虑以下宏:#defineCAT(X,Y)X##Y#defineCMB(A,B)CAT(A,B)#defineSLB_LOGGING_ALGORITHMCMB(Logging,SLB_ALGORITHM)其中SLB_ALGORITHM是定义的预处理器符号。如果我直接使用CAT而不是CMB,则SLB_ALGORITHM不会展开。为什么会这样?间接寻址究竟有何帮助?

c++ - 内联 lambda 是否会遭受与函数指针间接寻址相同的延迟

//approach1templatevoidf1(Tt,inta,intb){t(a,b);}//approach2voidf2(void(*g)(int,int),inta,intb){g(a,b);}voidg(inta,intb){//dosomething}intmain(){f1([](inta,intb){//dosomething},1,2);f2(&g,1,2);}我的问题是,f1和f2是否遭受相同的间接寻址延迟以获取要执行的函数的地址(假定lambda实现为函数对象)?如果lambda不是内联的怎么办?注意:我将函数f1声明为模板,以便将参数lambda类型的推导留

c++ - 是否有一种非间接、非 hack 的方法来保证 constexpr 函数只能在编译时调用?

目前,我们有两个主要的编译时评估选项:模板元编程(通常使用模板结构和/或变量)和constexpr操作1。templatestructsum_{enum{value=l+r};};//Withstruct.templateconstintsum=sum_::value;//Withstruct&var.templateconstintsub=l-r;//Withvar.constexprintmul(intl,intr){returnl*r;}//Withconstexpr.其中,我们保证所有四个都可以在编译时求值。templatestructCompileTimeEvaluable{

c++ - 可以使用 std::remove_pointer 从指针类型中删除所有间接寻址吗?

假设我有..int、int*、int**等。我可以使用std::remove_pointer或类似工具直接输入int吗?谢谢 最佳答案 是的。templatestructremove_all{typedefTtype;};templatestructremove_all{typedeftypenameremove_all::typetype;};std::remove_pointer本身在这里用处不大。 关于c++-可以使用std::remove_pointer从指针类型中删除所有间接寻

在模拟器上运行时,观察连接性不会在iOS侧**

我正在尝试在模拟器上运行我的项目,但是iOS侧没有激活,只有手表侧设法激活。这是我的ScoresInterfaceController.swift(观看侧)importWatchConnectivityclassScoresInterfaceController:WKInterfaceController,WCSessionDelegate{//UsedtosendinformationtotheiOSappvarapplicationDict=[String:Int]()//StartsasessiontocommunicatewiththeiOSappvarsession:WCSessio

c++ - 如何优化间接基数排序? (又名如何优化不可预测的内存访问模式)

我用C++编写了一个间接基数排序算法(间接,我的意思是它返回项目的索引):#include#include#includetemplatevoidradix_ipass(It1begin,It1constend,It2consta,size_tconsti,std::vector>&buckets){size_tncleared=0;for(It1j=begin;j!=end;++j){size_tconstk=a[*j][i];while(k>=ncleared&&ncleared=buckets.size()){buckets.resize(k+1);ncleared=bucket

c++ - 使用间接父类的方法

考虑以下代码:classuser_error:publicstd::runtime_error{public:usingstd::exception::what;explicituser_error(conststd::string&what_arg):std::runtime_error(what_arg){}};classwith_overriden_what:publicuser_error{public:with_overriden_what(conststd::string&val):user_error("user_error"),message(val){}std::st

c++ - 有间接仿函数吗?

我正在寻找一个一元仿函数,它将取消引用它的参数并返回结果。我当然可以写一个,只是看起来有些东西应该已经存在了。所以给定代码:constautovals={0,1,2,3};vectortest(size(vals),nullptr);iota(begin(test),end(test),data(vals));transform(cbegin(test),cend(test),ostream_iterator(cout,""),[](constauto&i){return*i;});LiveExample我希望有一个仿函数可以用来代替lambda。是否存在这样的事情,还是我只需要使用l