草庐IT

return-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++ - 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编译器。

C++ operator= 返回对 *this 的引用

看下面的代码:#includeusingnamespacestd;classWidet{public:Widet(intval=0):value(val){}Widet&operator=(Widet&rhs){value=rhs.value;return*this;}intgetValue(){returnvalue;}private:intvalue;};intmain(){Widetobj1(1);Widetobj2(2);Widetobj3(0);(obj3=obj2)=obj1;cout代码运行成功,输出为(使用VS2008):当我让operator=返回一个值而不是引用时:

为什么我遇到错误: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

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容器中的

c++ - 返回引用是什么意思?

我理解C++中引用的概念,我理解它们在函数参数中的作用,但我仍然对它们如何处理返回类型感到非常困惑。例如,在参数中使用时,这段代码:intmain(void){intfoo=42;doit(foo);}voiddoit(int&value){value=24;}类似于这段代码:intmain(void){intfoo=42;doit(&foo);}voiddoit(int*value){*value=24;}(知道每次doit的第一个代码示例中使用它时,编译器都会自动在value前面放置一个星号,但在后者中你每次尝试使用value时都必须在自己身上加上星号)那么,当用作引用时,下一段代

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