草庐IT

big_class

全部标签

c++ - template<class key, class type> 在 C++ 中的方法之前是什么意思?

我有这段代码,我试图理解遵循的约定,.cpp文件中定义的所有方法都有template写在他们面前。这是什么意思?例子://ConstructortemplateMyOperation::MyOperation(){//methodimplementation}//AmethodtemplateMyOperation::otherOperation(){//methodimplementation}谢谢 最佳答案 必须已经有一个很好的答案,但我也会把我的也扔进池中。C++允许程序结构的声明和实现分开进行。它源于C/C++程序员如何相互

c++ - 从子类到父类(super class)再到子类的转换?

我的程序需要处理不同种类的“笔记”:NoteShort,NoteLong...不同种类的笔记应该以不同的方式显示在GUI中。我为这些笔记定义了一个基类,叫做NoteBase.我将这些笔记存储在XML中;我有一个从XML文件读取并将笔记数据存储在vectorlist中的类.然后我发现我无法获取它们自己的类型,因为它们已经转换为NoteBase*!虽然if(dynamic_cast(ptr)!=NULL){...}可能有效,它真的太丑了。实现函数取NoteShort*或NoteLong*作为参数不起作用。那么,有什么好的方法可以解决这个问题吗?更新:谢谢大家的回复。我认为这也不应该发生——

c++使用计算参数调用父类(super class)构造函数

可能super简单,但是有人可以告诉我如何使用在子类构造函数中计算的参数调用父类(superclass)构造函数吗?像这样:classA{A(inti,intj);};classB:A{B(inti);};B::B(inti){intcomplex_calculation_a=i*5;intcomplex_calculation_b=i+complex_calculation_a;A(complex_calculation_a,complex_calculation_b);}//编辑:我编辑了示例,以便父类(superclass)接受两个相互关联的参数 最佳

c++ - 解决 "only static const integral data members can be initialized within a class"编译错误

以下创建全局对象会导致编译错误。#include"stdafx.h"#includeusingnamespaceSystem;usingnamespacestd;#pragmahdrstopclassTester;voidinput();classTester{staticintnumber=5;public:Tester(){};~Tester(){};voidsetNumber(intnewNumber){number=newNumber;}intgetNumber(){returnnumber;}}TestertesterObject;voidmain(void){cout>ne

解决:xxx has been compiled by a more recent version of the Java Runtime (class file version 55.0)

原因当前类是由jdk1.8版本编译,当前运行环境低于jdk1.8,故出现当前情况。javacode和name对应关系49=Java550=Java651=Java752=Java853=Java954=Java1055=Java1156=Java1257=Java1358=Java14解决方案升级当前项目jdk版本号,或者降低引用库编译的jdk版本号android{ ...compileOptions{sourceCompatibilityJavaVersion.VERSION_1_8targetCompatibilityJavaVersion.VERSION_1_8}}

c++ - 'must have an argument of class or enumerated type'到底是什么意思

我有一个头文件和一个.cpp文件。我需要为我的.h文件编写函数,但在我完全完成骨架.cpp文件之前出现错误。金钱.h#ifndefMONEY_H#defineMONEY_H#include#includeusingnamespacestd;classMoney{public:Money(intdollars,intcents);Moneyoperator+(constMoney&b)const;Moneyoperator-(constMoney&b)const;Moneyoperator*(doublem)const;Moneyoperator/(doubled)const;voidp

c++ - 避免过多的函数参数 : class-centered or function-centered approach?

您将如何修复以下传递过多参数的错误代码?voidhelper1(intp1,intp3,intp5,intp7,intp9,intp10){//...}voidhelper2(intp1,intp2,intp3,intp5,intp6,intp7,intp9,intp10){//...}voidfoo(intp1,intp2,intp3,intp4,intp5,intp6,intp7,intp8,intp9,intp10){helper1(p1,p3,p5,p7,p9,p10);helper2(p1,p2,p3,p5,p6,p7,p9,p10);}我看到两种不同的方法:方法一:将所有函

c++ - 虚拟功能 : Iterating over a vector<Base Class> that is populated with subclass objects

简短描述:我正在迭代一个vector,在vector中的每个对象上调用一个虚函数,以执行一系列操作。vector和迭代器一样属于基类。所有的对象都是child。当调用虚函数时,它会执行基类的函数。(真的)长描述:我正在尝试为具有一组行为的生物建模。我的基类是抽象的,只有两个函数(虚拟),所有子类都已覆盖:classBehavior{public:Behavior();~Behavior(void){}virtualvoidexecute(){}virtualBEHAVIOR_TYPEgetType(){returnm_Type;}protected:BEHAVIOR_TYPEm_Typ

c++ - 对 `typeinfo for class' 的 undefined reference 和对 `vtable for class' 的 undefined reference

这个问题在这里已经有了答案:Undefinedsymbols"vtablefor..."and"typeinfofor..."?(5个答案)关闭9年前。我正在处理C++中的继承。我想写一个程序来对两个数组进行加法和减法。这是我的代码:#include#include#includeusingnamespacestd;classroot{protected:intsize;double*array;public:virtual~root(){}virtualroot*add(constroot&)=0;virtualroot*sub(constroot&)=0;virtualistrea

c++ - 是否可以为 C++ +'s string class? And to concatenate "文字创建运算符函数?

我可以为C++的string类任意写一个operator+()函数,这样我就不用连接了字符串?例如,而不是做someVariable我可以添加一个operator+()这样我就可以了someVariable="concatenate"+"this";? 最佳答案 std::stringoperator+确实连接两个std::string。但是,您的问题是"concatenate"和"this"不是两个std::string;它们的类型是constchar[]。如果您想连接两个文字"concatenate"和"this"出于任何原因(