经典C++(C with Classes)的Call/Return特性,现代语言有哪些? [英] Call/Return feature of classic C++(C with Classes), what modern languages have it?

查看:31
本文介绍了经典C++(C with Classes)的Call/Return特性,现代语言有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C++ 的设计和演变的第 57 页,Stroustrup 博士谈到了一个特性,它最初是 C with Classes 的一部分,但它不是现代 C++(标准 C++)的一部分.该功能称为调用/返回.这是一个例子:

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++ 的等价物是哨兵对象:在函数的开头构造它,其构造函数实现 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 with Classes)的Call/Return特性,现代语言有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆