草庐IT

this-reference

全部标签

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - 具有固定实现的虚函数不使用 (*this) 的大多数派生类

假设我有以下代码:structZ;structA{virtualvoidDo(Z&z)const;};structB:publicA{};structZ{voiduse(Aconst&a){}voiduse(Bconst&b){}};voidA::Do(Z&z)const{z.use(*this);}现在,当我调用B.do,this的类型是A,这是有道理的,因为do的实现在A中定义.有什么方法可以调用B.do使用use(Bconst&)无需为do复制粘贴相同的代码来自A进入B?在我的实际代码中,我有大约15个(并且还在不断增加)派生自某个基类的类,必须为do复制粘贴相同的代码似乎很浪费

c++ - 摩西中对 `gzopen' 的 undefined reference

我目前正在尝试安装moses脚本,它是机器翻译工具moses的一部分,但不断出现错误:/home/moses/scripts/training/lexical-reordering/reordering_classes.cpp:349:undefinedreferenceto`gzopen'/home/moses/scripts/training/lexical-reordering/reordering_classes.cpp:353:undefinedreferenceto`gzwrite'/home/moses/scripts/training/lexical-reorderin

c++ - 在基类中调用 shared_from_this() 时的 bad_weak_ptr

我有一个SuperParent类,一个Parent类(派生自SuperParent)并且都包含一个shared_ptr到一个Child类(它包含一个weak_ptr到一个SuperParent)。不幸的是,我在尝试设置Child的指针时遇到了bad_weak_ptr异常。代码如下:#include#include#include#includeusingnamespaceboost;classSuperParent;classChild{public:voidSetParent(shared_ptrparent){parent_=parent;}private:weak_ptrpare

c++ - "undefined reference"(适用于 linux,但不适用于 Windows 上的 cygwin)

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:gcclinkererrorsonfedora:undefinedreference由于我在使用VC++时遇到了问题(函数重载不会发生在gcc上,因为我的项目合作伙伴正在Linux上编程),我在cygwin上切换到gcc,但我无法让程序运行这里也是(他能够毫无问题地编译相同的代码)我正在尝试编译$gcc-ID:/Programme/Boost_Library/boost_1_51ABI_new.cpp-oABI然后我得到大量这样的错误:/tmp/ccO4eSA2.o:ABI_new.cpp:(.text+0x

c++ - g++ 链接问题 : In function `_start' : (. text+0x20): undefined reference to `main'

我收到对主要错误的undefinedreference-即使我已经定义了主要,并且(AFAICT),我已经正确链接了它。这是我的代码和我使用的命令://################################################//proj1.h#ifndef__SCRATCH_PROJ1_H#define__SCRATCH_PROJ1_HintaddOne(inti);#endif/*__SCRATCH_PROJ1_H*///################################################//proj1.cpp#include"pr

c++ - 错误 "undefined reference to omp_get_wtime"

我找不到要在Windows下的GCC(4.8)中链接的库(Vista)。我尝试了-fopenmp-llibgomp-lgomp编译器指令,但没有任何效果。我已经有了带POSIX的GCC(所以如果启用C++11,std::thread可以正常工作)。问题似乎是搜索正确的库并没有提供有用的结果(甚至在GCC/MinGW文档中搜索)。所以基本上我无法得到thisanswer工作(答案声称适用于大多数编译器,但它没有提供有关如何使其工作的额外信息,因此我无法验证它是否真的工作)。最好现在提供额外的信息以使其在大多数系统上运行...... 最佳答案

c++ - 从 C++ 调用 Fortran 子例程,链接时 undefined reference

我有一个Fortran子例程,我想从C++程序中调用它。它需要一长串浮点参数并使用iso_c_binding内部模块:subroutineparasolve(......)bind(c,name='c_parasolve')use,intrinsic::iso_c_bindingimplicitnone....根据我所读的内容,我明白我需要使用C++的“extern”命令来定义外部函数,然后再调用它。我尝试了两种方法。第一个:extern"C"voidc_parasolve(....);在编译时返回“expectedunqualified-idbeforestringconstant”

c++ - 异常 : bad_weak_ptr while shared_from_this

当我这样做时出现异常:std::bad_weak_ptr->shared_from_this()templateclasspainter_record_t{.......private:std::shared_ptr_owner;}这里我想在构造函数中设置“问题”对象:templateclassstream_record_t:publicpainter_record_t{public:stream_record_t(std::shared_ptrowner):painter_record_t(owner){//...}}我有基类:classi_painter_t{public:virt

c++ - 对 `boost::iostreams::mapped_file_source::mapped_file_source()' 的 undefined reference

我正在测试boost的内存映射文件,但是一旦我声明了一个boost::iostreams::mapped_file,就像在这个程序中一样:#include//definesff_pipelineandff_Pipe#include#include#include#include#include#include#include#include"MapReduceJob.hpp"usingnamespaceff;intmain(intargc,char*argv[]){boost::iostreams::mapped_filemf;}使用这个makefile:#FastflowandBoo