草庐IT

reference-type

全部标签

c++ - 如何在 C++03 中使用 "dereference a type"?

如何在C++03中获取另一种类型的“解引用类型”?请注意,它可以是其他可取消引用的类型,例如std::vector::iterator.例如如果我有templatestructMyPointer{Tp;???operator*(){return*p;}};我怎样才能弄清楚用什么替换???和?(没有提升!我想知道如何自己解决。) 最佳答案 templatestructdereference;templatestructdereference{typedeftypenameTtype;};templatestructMyPointer{

c++ - 对 B::B & B::~B 的 undefined reference

我不断收到g++编译器的投诉,说下面的代码有问题。仔细检查后,我还是想不通为什么从embedMain.cpp中找不到B类的构造函数和析构函数。谁能给我一点提示?谢谢//embedMain.cpp#include"embed.h"intmain(void){Bb("helloworld");return0;},//embed.h#ifndefEMBED_H#defineEMBED_H#includeclassB{public:B(conststd::string&_name);~B();private:std::stringname;};#endif,//embed.cpp#includ

c++ - 错误 : ‘i’ does not name a type with auto

这个问题在这里已经有了答案:HowdoIenableC++11ingcc?(4个答案)关闭7年前。我是C++新手,这是我的程序#include#include#include#include#includeintmain(){staticconstdoublearr[]={16.0,2.2,77.5,29.0,24.0};std::vectorvec(arr,arr+sizeof(arr)/sizeof(arr[0]));std::transform(vec.begin(),vec.end(),vec.begin(),bind2nd(std::minus(),3.0));for(aut

c++ - 从 std::array 等获取 size_type 的惯用方法

由thisquestion触发,我想出了以下代码(在我的回答中是boost::array,但同样适用于std::array):template::size_typesize>voidDataTransform(std::arraydata){}我对::size_type一点都不满意.我必须以一定的大小进行实例化,才能知道size_type.对于std::array我本可以使用size_t,那么一般情况呢?如果size_type怎么办不是size_t?或者更一般的(即不适用于std::array)如果size_type怎么办?不同的尺寸是不同的(愚蠢但可能)?我知道这个问题相当学术,有很

c++ - 错误 : '...' does not name a type

我有一个工作项目。重新安排一些代码后,我尝试重新编译我的项目,然后奇怪的事情开始发生。查看编译器输出的这段摘录。我正在使用MinGWG++从Windows上的Eclipse进行编译。****BuildofconfigurationDebugforprojectPract2********InternalBuilderisusedforbuild****g++-O0-g3-Wall-c-fmessage-length=0-omove.o..\move.cppInfileincludedfrom..\/game.h:11:0,from..\/piece.h:10,from..\/move.

C++ 单例 undefined reference

我是C++的新手,正在尝试理解C++中的单例模式。myclass.h#ifndefMYCLASS_H#defineMYCLASS_HclassMyclass{public:staticMyclass*getInstance();private:Myclass(){}Myclass(Myclassconst&){}Myclass&operator=(Myclassconst&){}staticMyclass*m_instance;};#endif//MYCLASS_Hmyclass.cpp#include"myclass.h"Myclass*Myclass::getInstance(){

为什么我遇到错误:attributeError:'int'对象没有属性'type'

我正在将LLVMlite与Pyvex结合使用。我已经在llvmlite中定义了一些功能,如下所示:defint32(val):returnir.Constant(ir.IntType(32),val)defput64(putoffset,val):llvmtmp=builder.gep(regtag,(int32(0),int32(putoffset)),True)returnbuilder.store(val,llvmtmp)但是,当我想使用以下代码调用此函数时:forstmtinirsb.statements:ifisinstance(stmt,pyvex.IRStmt.Put):puto

c++ - 如何为 lambda 创建 'reference'?

我想捕获对lambda的“引用”,我认为函数指针可以解决问题,如下所示:int(*factorial)(int)=[&](intx){return(x但我得到cannotconvertfrommain::lambdatoint(_cdecl*)(int).那么指向lambda的正确方法是什么? 最佳答案 由于lambda不是无状态的,因此不能将其转换为函数指针。请改用std::function。std::functionfactorial=[&](intx){return(x 关于c++

java - 鸭子类型(duck typing)和泛型编程

我在SO里找了一会儿,没有找到一个明确的、笼统的答案,只有一些矛盾的、特殊的意见。[1]所以我想知道鸭子类型(ducktyping)和泛型编程之间有什么关系?(DTGP)。通过泛型编程,我特别提到了C++模板或Java泛型,但如果可能的话,与概念相关的一般性答案将受到欢迎。我知道泛型编程将在编译时处理,而duck类型将在运行时处理,但我不知道如何定位它们。最后,我不想展开辩论,所以我更喜欢诸如理由、理由之类的答案。[1]What'stherelationshipbetweenC++templateandducktyping? 最佳答案

C++11 decltype : How to declare the type that a pointer points to?

我有以下代码:#includeintmain(){int*a=newint(2);std::unique_ptrp(a);}导致这些错误信息:Infileincludedfroma.cpp:1:Infileincludedfrom/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/memory:81:/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/