本文介绍了调用/返回功能的经典C ++(C与类),什么现代语言有它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的第57页,Stroustrup博士谈到了一个最初C的一部分与类,但它不是现代C ++(标准C ++)的一部分。该功能称为 call / return 。这是一个例子:

On page 57 of The Design and Evolution of C++, Dr. Stroustrup talks about a feature that was initially part of C with Classes, but it isn't part of modern C++(standard C++). The feature is called call/return. This is an example:

class myclass
{
  call() { /* do something before each call to a function. */ }
  return() { /* do something else after each call to a function. */ }
  ...
};

我发现这个功能非常有趣。任何现代语言都有这个特殊的功能吗?

I find this feature very interesting. Does any modern language have this particular feature?

推荐答案

现代的C ++等价物将是一个sentry对象:一个函数,其构造函数实现 call(),并且在返回时(或异常退出),它的析构函数实现 return()

The modern C++ equivalent would be a sentry object: construct it at the beginning of a function, with its constructor implementing call(), and upon return (or abnormal exit), its destructor implements return().

这篇关于调用/返回功能的经典C ++(C与类),什么现代语言有它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:01