草庐IT

true_type

全部标签

c++ - 如何在线程中使用 while true?

谁能指出我在这段代码中尝试做的事情,因为SecondLoop线程根本无法访问?仅当我删除while(true)循环时,它才变得可访问。#include#includeusingnamespacestd;voidLoop(){while(true){(dosomething)}}voidSecondLoop(){while(true){(dosomething)}}intmain(){threadt1(Loop);t1.join();threadt2(SecondLoop);t2.join();//THISTHREADISUNREACHABLEATALL!returnfalse;}我之所

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++ - 为什么我不能使用 == true 检查变量是否有值?

if(10)是真的,但是if(10==true)是假的。有人能告诉我为什么第一种情况将数字转换为bool而第二种情况没有吗? 最佳答案 if(10)等同于if(10!=0),而if(10==true)是if(10==1)(因为true被提升为int类型的值1)。通俗地说:碰巧满足某些属性的两件事不会自动成为同一件事。(例如,donut和飞盘都是圆形的,但这并不意味着donut等于飞盘。整数和bool值都可以在bool上下文中进行评估,但这并不意味着每个整数都被评估为true等于每个truebool值。)

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++ - 为什么 ~(true^true) 不是真的? boolean 运算符(否定)适用于 `unsigned char` s,但不适用于 boolean 值? (C++)

我听说通常除了0之外的“一切”都是真的。但是现在我身上发生了非常奇怪的事情……或者我只是认为我以正确的方式做事,而我却没有。这是正在发生的事情:当我想检查a是否等价于b时,我可以使用NOT(aXORb)。当我检查unsignedchar时,一切正常,例如unsignedchara=5;unsignedcharb=3;unsignedcharc=~(a^b);给我c==249:a是:00000101,也就是5。b是:00000011,也就是3。~(a^b)是:11111001,即249。现在,让我们用bool来试试这个。cout这让我在控制台中:-1-2-2-10110false虽然我希

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:缺少类