强制执行函数调用的顺序?(enforce order of function calls?)

假设我有一个抽象基类,我想要一个纯粹的虚方法,它必须由派生类实现,但我想确保派生方法以特定顺序调用函数,我可以如何执行它?

IE

base class
virtual void doABC()=0;
virtual void A()=0;
virtual void B()=0;
virtual void C()=0;


// must call ABC in the correct order 
derived class public base
void doABC();

这就是为什么我更好地理解如何设计我的类来强制某人正确使用我的类。


Say I have a abstract base class and I want to have a pure virtual method which must be implemented by the derived class but I want to make sure that the derived method calls functions in a particular order what could I do to enforce it ?

I.E

base class
virtual void doABC()=0;
virtual void A()=0;
virtual void B()=0;
virtual void C()=0;


// must call ABC in the correct order 
derived class public base
void doABC();

This is just so I have a better understanding on how to design my classes to enforce someone to use my class correctly.


原文:https://stackoverflow.com/questions/10601943
2021-12-21 11:12

满意答案

我不知道numberpsymbolp ,布尔类型和其他类型谓词的确切历史,但是对于泛型类型谓词typep的可用性,没有必要对每个类型都有单独的谓词。 查看某些boolean类型的简短方法是(typep object 'boolean)


I don't know the exact history of numberp, symbolp, the boolean type, and other type predicates, but with the availability of the generic type predicate typep it is not necessary to have a separate predicate for every type. A short way to see if something is of type boolean is (typep object 'boolean).

相关问答

更多

什么是谓词?(What is a predicate?)

一个谓词的定义,可以在这里在各种来源在线查找: 一个逻辑表达式,其计算结果为TRUE或FALSE,通常用于指导代码中的执行路径。 参考: 软件测试。 马修·海登 The definition of a predicate, which can be found online in various sources such as here, is: A logical expression which evaluates to TRUE or FALSE, normally to direct th...

探究剩余与加入谓词(Probe Residual vs Join Predicate)

这些是不同的概念。 我们正在深入了解SQL Server如何计划它的查询的细节,而不是那些让人胆战心惊的地方! 但非常有趣的是,如果你正在研究这个领域,你将不会成为一个“小老鼠”。 本文描述了如何将一些谓词解释为“寻找”,首先排除许多行,以便只有少数谓词需要检查以确定它们是否与谓词的其余部分相匹配 - 残留谓词。 本文介绍如何处理连接,以及查询的详细信息如何导致关于是否存在连接谓词的决定,从根本上影响性能。 These are distinct concepts. We're right into...

如何在谓词中使用谓词“断言”(How to use the predicate “assert” in a predicate)

很难弄清楚到底在找什么,但我必须说它看起来非常像家庭作业。 这是你想要的? create_nbStation(L) :- compte(L, N), assert(nbStation(L, N)). It is quite difficult to figure out what exactly you are looking for, but I must say it does look very much like homework assignment. Is this what you...

如何构建用于查找的谓词?(How to build this predicate for use with Find?)

还有方便 all :: (a -> Bool) -> [a] -> Bool 它可以用来编写你的功能 find (all isDigit) There is also the handy all :: (a -> Bool) -> [a] -> Bool which can be used to write your function find (all isDigit)

为什么没有BOOLEANP谓词?(Why isn't there a BOOLEANP predicate?)

我不知道numberp , symbolp ,布尔类型和其他类型谓词的确切历史,但是对于泛型类型谓词typep的可用性,没有必要对每个类型都有单独的谓词。 查看某些boolean类型的简短方法是(typep object 'boolean) 。 I don't know the exact history of numberp, symbolp, the boolean type, and other type predicates, but with the availability of th...

与谓词非常相似的东西,但不是谓词(Something very similar to predicate, but not a predicate)

您正在寻找的一般术语是“代表” 。 虽然你不能直接做一些像predicate(item) = someValue; 在C#中,您可以使用Action和/或Func来执行您要执行的操作。 获取价值是更常见的做事方式,例如LINQ的Select可以实现如下: public static IEnumerable<TResult> Select<TSource, TResult>( this IEnumerable<TSource> source, Func<TSource, TResul...

Łukasiewicz谓词逻辑?(Łukasiewicz predicate logic?)

它看起来像你想要的: static <T> Predicate<T> p(Predicate<? super T> o){ //(I'm not sure what to name this) return new Predicate<T>(){ @Override public boolean test(T t) { return t == null || o.test(t); } @Override...

谓词......还是其他一些术语?(Predicate… or some other term?)

嗯,你从你的函数中返回具体的值,并且它们中没有任何模糊,你在三值逻辑域(有时称为三价)比在模糊域中更多。 例如,三价在电子(三态逻辑)中非常流行。 设备可以处于3种状态:逻辑1(真),逻辑0(假)和高阻抗。 Hm, you are returning concrete values from your function, and there is nothing fuzzy in them, you are more in three-valued logic domain (sometimes ...

获取调用谓词的名称(Get the name of the calling predicate)

在SWI-Prolog检查库(prolog_stack) 。 特别是,以下谓词的组合应该可以满足您的需求: get_prolog_backtrace/2 prolog_stack_frame_property/2 请注意 :这不容易移植到其他Prolog系统,并且很可能有更优雅,更有效的方式来满足您的需求。 例如,执行所描述的一种方法是使用term_expansion/2 :您可以通过其中一个参数表示调用上下文的方式扩展特定目标。 这在运行时非常便携,非常高效,您可以静态检查生成的扩展。 In S...

使用DapperExtensions进行谓词化(Predicate with DapperExtensions)

我没有重新编写,但看起来问题部分在于你使表达式比示例更复杂。 作为建议,请尝试: public IEnumerable<T> Find<TValue>(Expression<Func<T, TValue>> expression, TValue value) { using (IDbConnection cn = GetCn()) { cn.Open(); var predica...

相关文章

更多

两种js function 声明方式

http://helephant.com/2012/07/14/javascript-function ...

Heritrix源码分析(二) 配置文件order.xml介绍

本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.javaeye.co ...

function-Oceanus配置说明

作用: 作为 table 的子节点,用于声明路由规则 属性: ref – Function 类型的 b ...

MyBatis动态参数order by的设置

mybatis动态参数一般是这样的 and status=# {status} 如果你在order b ...

error C2668: 'M' : ambiguous call to overloaded function

以下是代码: #include&lt;iostream&gt;using namespace std ...

Heritrix源码分析(三) 修改配置文件order.xml加快你的抓取速度

本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.javaeye.co ...

自定义路由逻辑函数-Oceanus编码调用

实现接口: com.bj58.oceanus.core.shard.Function 实现方法: pu ...

怎么用quartz控制任务的执行顺序

最近接手一个项目,通过web方式配置定时调度,一个调度有多个步骤,每个步骤的作用都不同,并且相互依赖。 ...

求一个group by后面字段顺序影响结果的例子

select a,b ,sum(e) from test group by a,b order by ...

Scala函数定义与调用

定义一个函数的格式是def 函数名([参数名[:参数类型][,参数名[:参数类型]......]])[ ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本