草庐IT

class_initialize

全部标签

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++ - 我们什么时候应该使用圆括号 ( ) 与 initializer { } 语法来初始化 C++11 中的对象?

这个问题在这里已经有了答案:Whentousethebrace-enclosedinitializer?(3个答案)关闭6年前。已更新我已经通过链接(例如Whentousethebrace-enclosedinitializer?)了解何时应该使用{}大括号初始化,但没有给出何时应该使用括号()的信息与初始值设定项{}在C++11/14中初始化对象的语法?建议使用哪些标准做法()在{}?在极少数情况下,例如vectorv(10,20);或autov=vector(10,20);,结果是std::vector有10个元素。如果我们使用大括号,结果是std::vector有2个元素。但这取

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

c++ - std::unique_ptr 删除函数,initializer_list - 驱动分配

全部,当我使用初始化列表格式实例化小部件数组时,指向成员变量小部件实例的裸指针可以编译,但在更改为std::unique_ptr后,gcc会给出有关已删除函数的编译错误。$uname-aLinux..3.5.0-21-generic#32-UbuntuSMP2012年12月11日星期二18:51:59UTCx86_64x86_64x86_64GNU/Linux$g++--versiong++(Ubuntu/Linaro4.7.2-5ubuntu1)4.7.2此代码给出以下编译器错误:#include#includeclassWidget{public:Widget(){}};class

c++ - std::initializer_list 的底层结构是什么?

第一部分:std::initializer_list是C++11的一个非常有用的特性,所以我想知道它是如何在标准库中实现的。从我读到的here,编译器创建一个T类型的数组并给出指向initializer_list的指针.它还声明复制initializer_list将创建一个引用相同数据的新对象:为什么会这样?我会猜到它要么:为新的initializer_list复制数据将数据的所有权转移到新的initializer_list第二部分:来自std::vector的众多在线引用资料之一构造函数:vector(initializer_listil,constallocator_type&al

解决: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