草庐IT

CLASS_NAME

全部标签

C++ 'class' 类型重定义

我第一次尝试使用C++中的类。我的circle类和关联的头文件工作正常,然后我移动了一些文件,从那以后一直收到错误,我在下面显示了错误。c:\circleobje.cpp(3):errorC2011:'CircleObje':'class'typeredefinitionc:\circleobje.h(4):seedeclarationof'CircleObje'CircleObje.h#ifndefCircleObje_H#defineCircleObje_HclassCircleObje{public:voidsetCol(floatr,floatg,floatb);voidset

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)接受两个相互关联的参数 最佳

解决在idea上连接linux开启的redis服务失败Failed to connect to any host resolved for DNS name.(史上最强+最细解决方案)

今天在idea上连接reids服务器时出现错误FailedtoconnecttoanyhostresolvedforDNSname.那么我们来一步一步来进行如下步骤。首先找到自己的redis.conf文件,可以使用这个搜索按钮直接搜索redis.conf文件(因为不同人的redis.conf文件可能不一样)找到该文件后我们需要修改如下几个地方。(1)、daemonizeyes大概在136行(2)、protected-modeno大概在88行(3)、注释掉bind127.0.0.1大概在69行这里需要注意的是注释的不是上面的而是箭头所指的地方。修改完成后我们wq保存退出。下面是打开端口6379(

C++ 错误 : Type Name is Not Allowed

我正在尝试学习指针参数中的新类(class),我想让函数senior和everyoneElse接受指针x,但是当我尝试使用指针pAge调用函数时,它显示错误:类型名称是不允许的。怎么了?#includeintsenior(int*x);inteveryoneElse(int*x);usingnamespacestd;intmain(){intage(0);int*pAge(&age);cout>age;if(age>59)senior(int*pAge);elseeveryoneElse(int*pAge);return0;}intsenior(int*x){return*x;}int

c++ - 在 C++ 中传递变量 "name"

我目前仅使用以下模板来检查NULL指针,如果为NULL,则将错误消息打印到日志文件,然后返回false。templatestaticboolisnull(T*t,std::stringname=""){_ASSERTE(t!=0);if(!t){if(!(name.length()))name="pointer";PANTHEIOS_TRACE_ERROR(name+"isNULL");returnfalse;}returntrue;}我目前这样调用它:if(!(isnull(dim,BOOST_STRINGIZE(dim))))returnfalse;如果您注意到我需要将要打印到日志

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