草庐IT

Class-Path

全部标签

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++ - CMake find_path 包含目录前缀

我正在为OpenNI编写一个最小的Find*.cmake。找到我写的头文件find_path(OPENNI_INCLUDE_PATHXnOS.h)按预期工作(OPENNI_INCLUDE_PATH的值为/usr/include/ni)。但是,在我的文件中,我必须包含标题#include我怎样才能去掉ni前缀,这样我就可以写了#include第一个包含的问题是包含了XnCppWrapper.h,并且此文件再次包含一些Xn*.hheader,但没有ni前缀。这会导致编译器错误。 最佳答案 总是有您用于find_path的路径匹配您的#i

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

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

c++ - 从 ‘boost::filesystem3::path’ 到非标量类型‘std::string’的 boost 错误转换

我有代码:std::stringfirstFile=boost::filesystem::path(first->name()).leaf();但是报错:errorconversionfrom‘boost::filesystem3::path’tonon-scalartype‘std::string我该如何解决?谢谢。 最佳答案 std::stringfirstFile=boost::filesystem::path(first->name()).leaf().string();另请注意,leaf函数已弃用并在Boost.Files

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);}我看到两种不同的方法:方法一:将所有函