草庐IT

final-class

全部标签

c++ - 由于父类(super class)(按值传递)导致的重载构造函数调用不明确

我围绕GSL的某些部分编写了一些C++包装器并遇到了以下难题(对我来说)。代码(精简到最基本的部分)如下:#includestructgsl_vector_view{};classVector:protectedgsl_vector_view{public:Vector(constVector&original);Vector(constgsl_vector_viewview);};classAutoVector:publicVector{public:explicitAutoVector(constsize_tdims);};voiduseVector(constVectorb){}

c++ - 错误 : Invalid base class C++

谁能解释一下是什么导致了这个错误?Error:Invalidbaseclass我有两个类,其中一个派生自第二个:#if!defined(_CGROUND_H)#define_CGROUND_H#include"stdafx.h"#include"CGameObject.h"classCGround:publicCGameObject//CGameObjectissaidtobe"invalidbaseclass"{private:boolm_bBlocked;boolm_bFluid;boolm_bWalkable;public:booldraw();CGround();CGround

c++ - 将子类对象传递给采用父类(super class)对象的函数

假设以下代码:classEvent{public:virtualvoidexecute(){std::cout执行时,程序输出“Eventexecuted.”,但我想执行SubEvent。我该怎么做? 最佳答案 您正在按值传递Event。该函数获取自己的参数拷贝,这是一个Event对象,而不是SubEvent。您可以通过传递引用来解决此问题:voidexecuteEvent(Event&e){//^e.execute();}这叫做objectslicing.这相当于:SubEventse;Evente{se};e.execute()

c++ - `template <class> friend class Foo` 是什么意思?

我正在探索boost::iterator_facade并遇到了这段代码:friendclassboost::iterator_core_access;templatefriendclassIterator;第二行是什么意思?我熟悉friend类,但我想我没见过template在任何事情之前。这里是上下文:templateclassnode_iter:publicboost::iterator_facade,Value,boost::forward_traversal_tag>{public:node_iter():m_node(0){}explicitnode_iter(Value*p

c++ - C++ 'final' 方法注释对类设计有何 promise ?

从语言的角度来看,我知道C++(自C++11起)中的final方法注释的作用。classBase{virtualvoidmethod();};classLocked:publicBase{virtualvoidmethod()final;};任何派生自Locked的类都不能再覆盖method。但是从OOP的角度来看,它对API和契约(Contract)有什么看法?正如已经要求的Java,作为Locked的类作者,关于现在整个类的设计,我必须注意什么,我promise什么?例如:我可以想象,通过使用final注释,我是在说“这个方法的行为不会改变”。但是,如果我在method()中调用其

c++ - 错误 : class template partial specialization contains a template parameter that cannot be deduced

我很感激帮助弄清楚我的代码中出现的这个问题是怎么回事,我已将其简化为以下内容:typedefunsignedshortushort;templatestructFoo{};//Specialization--workswhennotaspecializationtemplateclassContainer,templateclass>classMetaFunction>structFoo::Type>>{//typedefContainer::Type>TestType;//OK};intmain(){}在编译(gcc5.4.0)时出现错误:Test.cpp:14:8:error:te

c++ - 需要 : C++ class for maintaining a 1-dimensional list of extents

我正在寻找可以维护一维范围列表的C++类。每个范围都定义为一个(start,len)对。我希望能够向列表中添加额外的范围并自动合并它们。也就是说,如果我们在列表中有(0,5)和(10,5),并且添加了(5,5),新列表应仅包含(0,15)。范围永远不会从列表中删除。有这样的东西吗?谢谢。 最佳答案 您正在寻找Boost.Icl。它完全符合您的描述。http://www.boost.org/doc/libs/1_52_0/libs/icl/doc/html/index.html 关于c++

c++ - "no base classes of the same type as the first non-static data member"

我askedthisawhileago在comp.std.c++上并没有得到答复。我只是要在那里引用我的帖子,稍作修改。标准布局类的最后一个要求9/6是必要的还是有用的?提供了脚注解释:Thisensuresthattwosubobjectsthathavethesameclasstypeandthatbelongtothesamemost-derivedobjectarenotallocatedatthesameaddress(5.10).单独来看,脚注是不正确的。两个空基类公共(public)基类可能会产生基类的两个实例同一个地址。structA{};structB:A{};str

Spring XML 命名空间 : How do I find what are the implementing classes behind them?

在我的Spring3.1应用程序中,有时我需要更改上下文文件中某些Spring命名空间的默认行为。为此,我创建了实现某些接口(interface)或扩展Spring使用的默认类的自定义类。但我发现很难确切知道Spring在其命名空间后面使用的那些类是什么!找到它们需要哪些步骤?例如,安全命名空间:类似的东西:...如何找到“”命名空间使用了哪些类?我没有通过查看http://www.springframework.org/schema/security/spring-security-3.1.xsd找到信息!我应该去哪里看? 最佳答案

Spring XML 命名空间 : How do I find what are the implementing classes behind them?

在我的Spring3.1应用程序中,有时我需要更改上下文文件中某些Spring命名空间的默认行为。为此,我创建了实现某些接口(interface)或扩展Spring使用的默认类的自定义类。但我发现很难确切知道Spring在其命名空间后面使用的那些类是什么!找到它们需要哪些步骤?例如,安全命名空间:类似的东西:...如何找到“”命名空间使用了哪些类?我没有通过查看http://www.springframework.org/schema/security/spring-security-3.1.xsd找到信息!我应该去哪里看? 最佳答案