草庐IT

this_call

全部标签

c++ - 调试 :FASTLINK - What is this error?

#include#include#includeusingnamespacestd;intmain(){FILE*fPtr=fopen("english.txt","r");if(fPtr==NULL){coutfreq;while(!feof(fPtr)){fscanf(fPtr,"%s",word);freq[word]++;}multimapfreq_rev;map::iteratorit;for(it=freq.begin();it!=freq.end();it++)freq_rev.insert(make_pair(it->second,it->first));multima

c++ - 如何将 'this' 作为参数传递给另一个没有循环依赖的类构造函数?

我特别想到策略模式(设计模式,GoF94),其中建议传递给策略构造函数的上下文可以是包含策略(作为成员)本身的对象。但以下内容不起作用://analysis.hclassStrategyBase;classStrategy1;classStrategy2;classAnalysis{...voidChooseStrategy();private:StrategyBase*_s;...};//analysis.cppvoidAnalysis::ChooseStrategy(){if(...)_s=newStrategy1(this);elseif(...)_s=newStrategy2(

c++ - 使用 C++0x : call to deleted constructor of 时的 clang++ 错误消息

您好,我已经将我的Xcode升级到4.2版,并将clang++升级到以下版本:Appleclangversion3.0(tags/Apple/clang-211.10.1)(basedonLLVM3.0svn)Target:x86_64-apple-darwin11.2.0Threadmodel:posix当尝试使用clang-std=c++0x编译以下代码时#include#include#includeclassilpConstraintImpl{public:virtual~ilpConstraintImpl(){}};classilpConstraint{public:ilpC

c++ - 如果我在 lambda 函数中使用 [this] 而不是 [=] 是否有任何性能提升?

据我了解,[=]复制函数体内使用的所有变量,而[this]仅复制this指针。但是查看示例,我发现[=]被广泛使用,其中[this]或[this,foo]就足够了。是否有任何理由(例如性能提升)使用[this]而不是[=]? 最佳答案 没有性能提升,因为正如您所说,只有您在lambda中实际使用的变量会被复制用于[=]。†这主要是编码人员的懒惰和保持lambda头的简洁。如果您使用新变量,则必须扩展捕获子句以包含这些变量,等等。然而,有时,您希望/必须是明确的,例如当您想要混合按引用和按值捕获时。†请注意,目前,以下代码段中的[=]

C++ this指针总是const

对于类X的非const成员函数,this指针的类型为X*const。然后,成员函数的this指针始终为const。那么,我们是否总是需要像这样进行const转换:voidfoo::p(){const_cast(member)=1;}我是不是漏掉了什么? 最佳答案 ForanonconstmemberfunctionofclassX,thispointerisoftypeX*const.不,非const成员函数中的this指针的类型只是X*(而且它是一个右值)。但即使this是X*const,这仍然不会阻止您更改数据成员。您的代码示例

c++ - std::reverse_copy "error: function call has aggregate value"

#include#include#include#includeusingnamespacestd;intmain(){intarrA[]={1,2,3,4,5,6,7,8,9};vectorvecIntA(arrA,arrA+sizeof(arrA)/sizeof(arrA[0]));vectorvecIntB(vecIntA.size());//copy((vecIntA.rbegin()+3).base(),(vecIntA.rbegin()+1).base(),vecIntB.begin());//OKvector::iterators=(vecIntA.rbegin()+3)

c++ - 如果在类中不使用 "this"会发生什么情况?

假设我有以下类(class):classfoo{public:intsomeNum;voidcalculation(intsomeNum);};定义:voidfoo::calculation(intsomeNum){someNum=someNum;}现在在someNum=someNum行中,指的是哪个someNum?如果我这样做:this->someNum=someNum那第二个someNum是什么?避免这个问题的好的命名风格是什么?例如,在objective-c中,在成员变量名前加上前缀“_”。(例如:_someNum); 最佳答案

c++ - enable_shared_from_this 需要什么?

这个问题在这里已经有了答案:Whatistheusefulnessof`enable_shared_from_this`?(6个答案)关闭6年前。我是C++11的新手,我遇到了enable_shared_from_this。我不明白它试图达到什么目的?所以我有一个使用enable_shared_from_this的程序。structTestCase:enable_shared_from_this{std::shared_ptrgetptr(){returnshared_from_this();}~TestCase(){std::coutobj1(newTestCase);std::sh

c++ - 将 "this"转换为引用指针

假设我有一个结构structFoo{voidbar(){do_baz(this);}/*Seeeditbelowvoiddo_baz(Foo*&pFoo){pFoo->p_sub_foo=newFoo;//forexample}*/Foo*p_sub_foo;}GCC告诉我temp.cpp:Inmemberfunction‘voidFoo::bar()’:temp.cpp:3:error:nomatchingfunctionforcallto‘Foo::do_baz(Foo*const)’temp.cpp:5:note:candidatesare:voidFoo::do_baz(Foo

c++ - 模板调用 : Actual specialization not called

#includeusingnamespacestd;templatevoidtest(){coutvoidtest(){cout();//expectedoutput2butactualoutput1}为什么输出是1而不是2? 最佳答案 test(注意:末尾没有括号)会产生您期望的结果。写成test用“不带参数并返回std::string的函数”类型实例化模板 关于c++-模板调用:Actualspecializationnotcalled,我们在StackOverflow上找到一个类似