草庐IT

difference_type

全部标签

c++ - C/C++ sizeof 运算符 : Why does sizeof( 'a' ) return different values?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Sizeofcharacter('a')inC/C++我是C的初学者,对此感到困惑。C:我尝试使用“%zu”修饰符在C中打印sizeof('a'),它打印出值4。C++:在C++中使用cout打印sizeof('a')和printf(使用上述格式)都打印出值1。我认为正确的值应该是1,因为'a'将被视为字符。为什么它不在C中返回4?两种语言的操作大小是否不同?如果是这样,有什么区别,为什么它会返回不同的值?我在这两种情况下都使用了gcc编译器。

为什么我遇到错误: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++ - 新手在这里 : Different results on PC and MAC. 为什么?

这个问题在这里已经有了答案:Whyaretheseconstructsusingpreandpost-incrementundefinedbehavior?(14个答案)关闭8年前。我现在正在尝试学习C/C++的基础知识。我正在学习Lynda.com上的类(class)我的问题涉及第4章“C/C++基本培训类(class)中的宏警告”中的一系列代码。我已按照所有设置程序在Mac上正确设置Xcode和Eclipse,在PC上正确设置Eclipse。当我在MAC和PC上运行这段代码时,我得到了不同的结果。只是想了解为什么会发生这种情况,以及我可以做些什么来在两者上获得相同的结果。代码如下:

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/

c++ - 根据 value_type 调用适当的构造函数 : integer or float

我有一个函数,它使用均匀分布将最小值和最大值之间的随机值填充到容器中。#include#include#include#includetemplatevoiduniform_random(TContainer&container,consttypenameTContainer::value_typemin,consttypenameTContainer::value_typemax){std::random_devicerd;std::mt19937gen(rd());//Belowlinedoesnotworkwithintegerscontainerstd::uniform_rea

c++ - 在哪里可以找到 C++ STL 中 vector 的 size_type 定义?

将vector的size()函数的结果转换为unsignedint似乎是安全的。不过,我怎么能确定呢?我的文档不清楚size_type是如何定义的。 最佳答案 不要假定容器大小的类型(或在其中键入的任何其他内容)。今天?目前最好的解决方案是使用:std::vector::size_type其中T是您的类型。例如:std::vector::size_typei;std::vector::size_typej;std::vector>::size_typek;(使用typedef可以帮助使其更好地阅读)对于迭代器和“内部”STL容器中的

Qt : has initializer but incomplete type 中的 C++ 错误

voidFindWords::getTextFile(){QFilemyFile(":/FindingWords2.txt");myFile.open(QIODevice::ReadOnly);QTextStreamtextStream(&myFile);QStringline=textStream.readAll();myFile.close();ui->textEdit->setPlainText(line);QTextCursortextCursor=ui->textEdit->textCursor();textCursor.movePosition(QTextCursor::S

c++ - "' void* ' is not a pointer-to-object type"在没有 void* 的代码中?

我的代码有问题。在Xcode或使用C++11编译器中,此代码运行良好。但是,当我将此代码提交给在线法官时,判决显示“编译错误”。我认为他们使用的是C++4.7.1编译器,当我尝试编译它(使用Ideone)时,它说:prog.cpp:Infunction'voidprintArray(int)':prog.cpp:27:error:'void*'isnotapointer-to-objecttypeprog.cpp:27:error:'void*'isnotapointer-to-objecttypeprog.cpp:27:error:'void*'isnotapointer-to-ob

c++ - "missing type specifier"构造函数声明错误

我在2个不同的文件中有2个类:正则矩阵.h:#ifndef_RM_H#define_RM_H#include"SparseMatrix.h"...classRegMatrix{...RegMatrix(constSparseMatrix&s){...}//ctor...};#endif稀疏矩阵.h:#ifndef_SM_H#define_SM_H#include"RegMatrix.h"...classSparseMatrix{...SparseMatrix(constRegMatrix&r){...}//ctor...};#endif在构造函数行上我得到了错误:错误C4430:缺少类