草庐IT

non-printing

全部标签

c++ - 如何在 gdb 中为 pretty-print 调用构造函数

在使用GDB进行调试时,我想将一个方便的变量设置为新构造的值。我正在使用Qt框架进行编程,所以我想创建一个QString,但这与问题无关,因为我想知道如何对任何类执行此操作。我试过了(gdb)set$str='QString::QString("abc")'Nosymbol"QString::QString("abc")"incurrentcontext.(gdb)set$str=QString::QString("abc")CannotresolvemethodQString::QStringtoanyoverloadedinstance(gdb)set$str=QString("a

c++ - gcc-4.9.2 : non-type template parameter

我在gcc-4.9.2上有一个奇怪的编译错误,相同的代码在其他编译器上工作,比如gcc-4.8或我能找到的任何clang。问题与non-typetemplate-arguments有关.所以考虑一下:#include#includeinttemplateParam;templatestructTestTemplate{intvalue(){}};templateintTestTemplate::value(){returntemplateParam;}TestTemplatetestVariable;intmain(){std::cout我在gcc-4.9.2中遇到以下错误:prog.

c++ - constexpr 与 std::array - "Non-type template argument is not a constant expression"

这个问题在这里已经有了答案:Errorusingaconstexprasatemplateparameterwithinthesameclass(2个答案)关闭9年前。我正在尝试实现以下内容:#include#includeclassClass2{};classClass1{public:staticconstexpruint8_tGetMax(){return5;}staticconstexpruint8_tGetMin(){return0;}staticconstexpruint8_tGetCount(){returnGetMax()-GetMin()+1;}private:std

c++ - Git Diff Indent/Pretty Print/Beautify Before Diff

有没有办法让Gitindent/beautify/pretty在diff之前打印两个版本的C++源文件?我不希望Git向我显示在有人自动格式化代码后引入的无数更改。示例用法:我点击gitdifftool--indent-before-diffingpath/to/file并在path/to/file的原始版本之后获取更改>和path/to/file的修改版本已经缩进。 最佳答案 如果您能找到为您缩进的应用程序,您可以使用描述的方法here对于odt文件:Addthefollowinglinetoyour.gitattributesf

C++ 风格指南 : why to have non-lvalues on the left side?

合一C++codingstyleguide,我发现了一个特别的建议(第41页,建议编号53):Alwayshavenon-lvaluesontheleftside(0==iinsteadofi==0).我不明白这有什么用?要坚持这种做法吗?我不是,我也不知道为什么他是个好习惯。我能想到的唯一优点是,这将避免将无意分配误认为是比较(if(foo=0){}与if(foo==0){})对于我为什么要使用它,您有任何其他想法吗? 最佳答案 是的,你猜对了。这是好的,老Yodacondition!!!

c++ - C/C++ 拼图 : To print values from 1. .15 15..1 带有一个 for 循环

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭10年前。这是我同事给的,打印值1234....1515.....4321只有一个for循环,没有函数,没有goto语句,没有使用任何条件语句或三元运算符。所以我使用类型转换来解决它,但这不是一个精确的解决方案,因为15没有被打印两次。intmain(){inti,j;for(i=1,j=0;j输出:1234...151413....21任何替代解决方案?

c++ - `invalid initialization of non-const reference` 是什么意思?

编译此代码时,我得到以下error:Infunction'intmain()':Line11:error:invalidinitializationofnon-constreferenceoftype'Main&'fromatemporaryoftype'Main'这是我的代码:templatestructMain{staticMaintempFunction(){returnMain();}};intmain(){Main&mainReference=Main::tempFunction();//我不明白为什么?谁能解释一下? 最佳答案

c++ - 我可以在类定义中放置 "non-static blocks"代码吗?

C++中有非静态block吗?如果不是,如何优雅地模拟?我想替换像这样的东西:-classC{public:voidini(){/*somecode*/}};classD{std::vectorregis;//willini();laterpublic:Cfield1;public:Cfield2;public:Cfield3;//wheneverIaddanewfield,Ihaveto...#1public:D(){regis.push_back(&field1);regis.push_back(&field2);regis.push_back(&field3);//#1...al

c++ - constexpr 类的设计 : merging constexpr and non-constexpr versions?

考虑一个在运行时只包装一个值的类:templateclassNonConstValue{public:NonConstValue(constType&val):_value(val){;}Typeget()const{return_value;}voidset(constType&val)const{_value=val;}protected:Type_value;};以及它的constexpr版本:templateclassConstValue{public:constexprConstValue(constType&val):_value(val){;}constexprTypeg

c++ - xvalues : differences between non class types and class types

考虑下面的最小示例:#includestructS{};intmain(){Ss;std::move(s)=S{};}它编译没有错误。如果我改为使用非类类型,则会收到错误。例如,以下代码无法编译:#includeintmain(){inti;std::move(i)=42;}枚举、作用域枚举等也是如此。错误(来自GCC)是:usingxvalue(rvaluereference)aslvalue这背后的原理是什么?我想这是对的,但我想了解我可以对除非类之外的所有类型执行此操作的原因是什么。 最佳答案 C++允许对类对象右值进行赋值,