草庐IT

LOG_TYPE

全部标签

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.

为什么我遇到错误: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++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++ - 为什么我的 n log(n) 堆排序比我的 n^2 选择排序慢

我已经实现了两种算法来对元素进行从高到低的排序。第一个在实际RAM模型上花费二次时间,第二个花费O(nlog(n))时间。第二个使用优先级队列来减少。这里是时间,是上述程序的输出。第一列是随机整数数组的大小第二列是O(n^2)技术的时间(以秒为单位)第三列是O(nlog(n))技术的时间(以秒为单位)96001.926637.5886598001.937057.67376100002.086478.19094尽管复杂性存在巨大差异,但就所考虑的数组大小而言,第3列大于第2列。为什么会这样?C++实现优先级队列慢吗?我在Windows7、VisualStudio201232位上执行了这段

Verilog求log10和log2近似

Verilog求log10和log2近似Verilog求10对数近似方法,整数部分用位置index代替,小数部分用查找表实现参考:Verilog写一个对数计算模块Log2(x)FPGA实现对数log2和10*log10