Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call/Return feature of classic C++(C with Classes), what modern languages have it?

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?

like image 427
Khaled Alshaya Avatar asked Apr 22 '10 03:04

Khaled Alshaya


People also ask

What is modern C++?

Modern C++ emphasizes the principle of resource acquisition is initialization (RAII). The idea is simple. Resources (heap memory, file handles, sockets, and so on) should be owned by an object. That object creates, or receives, the newly allocated resource in its constructor, and deletes it in its destructor.

Does Bjarne Stroustrup still work on C++?

Bjarne Stroustrup created C++, one of the most popular embedded programming languages. He is still working on the latest revisions of the C++ standard.


1 Answers

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().

like image 109
Potatoswatter Avatar answered Oct 14 '22 03:10

Potatoswatter