Topic: fcn - call operator overloading
Author: cadi@sumba.uni-paderborn.de (Carsten Ditze)
Date: 22 Aug 1994 09:22:39 GMT Raw View
Hi,
I've got two questions regarding the understanding of two issues in the current
C++ language:
(1) overloading of the function call operator:
What I was first expecting when I read that the function call operator may be
overloaded as well as any other arithmetic operators are allowed to, is that
the invocation process of a method defined in a class may be user-defined.
Example:
Given a method X::foo(), and X::operator()() is user-defined, I'd
expected that the folling pseudo-implementation would be possible:
X::operator()() {
time = getTime();
"call the true method, e.g. foo()";
timeUsed = time - getTime();
}
so that the call of a method like X::foo could result in executing a
header code and a trailing code like it is done in this example to measure
the time used in each method.
However, examing my C++ book tought me that 'overloading' in the case of
fcn. call operatores can be used to make a variable of X behave like a
method which (in my opinion) has not much in common with 'overloading'.
I've studied the FAQ but unfortunatly I found no way to deal with an
overloading like presented in the given pseudo code. I really miss this, since
it could be used in many ways (time measurement, and writing code that loads
itself on demand for instance).
Is there any chance, that this will be part of C++ some day, or is there some
other elegant(!) possibility to implement this?
(2) concerning: "pointer to member method is completely different from pointer
to a function"
I've learned from the FAQ, that it is not possible to get the address
pointing to the code of a method. However, if you're working with threads,
you'd like to run some methods of a class in parallel. Unfortunately, all
thread packages are C-based and require a pointer to the code to be run by a
new thread. The only way to get this in C++, is to use either static or
friend functions. This looks like a workaround to me, and I feel that the
power of some language constructs such as inheritance degrades using this
technic.
Question: Is there some discussion to integrate multi-threaded classes in
the standard?
Thanks for your answers,
Carsten
--
+------------------------------------------------------------------------+
| Carsten Ditze | e-mail: cadi@uni-paderborn.de |
| University of Paderborn | or: cadi@pbinfo.uucp |
| FB 17 (Dept. of Math. & CS) | or: ...!uunet!unido!pbinfo!cadi |
| | voice: +49 +5251 60-2074 |
| 33095 Paderborn, Germany | fax: +49 +5251 60-3427 |
+------------------------------------------------------------------------+
Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 26 Aug 1994 05:23:18 GMT Raw View
>>>>> Carsten Ditze <cadi@sumba.uni-paderborn.de> writes:
> (1) overloading of the function call operator:
> What I was first expecting when I read that the function call operator may be
> overloaded as well as any other arithmetic operators are allowed to, is that
> the invocation process of a method defined in a class may be user-defined.
g++ used to allow you to do that, for implementing distributed computing
sorts of things. The code has rotted, though, and doesn't currently work.
Jason