草庐IT

storage-class-specifier

全部标签

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++ - 在 Windows 7 上使用 SHA2-512 (CALG_SHA_512) 返回 "Invalid Algorithm Specified"

我尝试在Windows7上使用SHA2-512和CryptoAPI,但是,调用CryptCreateHash失败,GetLastError()=2148073480=0x80090008,即“无效算法”指定的”。根据https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549%28v=vs.85%29.aspxSHA2应该从WindowsXPSP3开始可用。这是我使用的代码:HCRYPTPROVhCryptProv;CryptAcquireContext(&hCryptProv,nullptr,nullptr,PRO

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++ - 错误 MSB8008 : Specified platform toolset (v120) is not installed or invalid

这个问题在这里已经有了答案:WhatdoIneedtoinstallforC++project/VS2013onTeamCityserverorTeamFoundationBuildService?(1个回答)关闭8年前。我已经下载了一个C++项目。我打开了.sln文件并尝试构建项目。我收到以下错误:错误MSB8008:指定的平台工具集(v120)未安装或无效。请确保选择了受支持的PlatformToolset值。我已经检查过平台工具集是否设置为v120。这里有什么问题?