alias template parameters - opCall caller! example breaks in Programming in D, page 530
Brother Bill
brotherbill at mail.com
Sat Aug 23 12:50:40 UTC 2025
On page 530 of Programming in D, we have this code snippet:
```
class C {
void opCall() {
writeln("C.opCall called.");
}
}
// ...
auto o = new C();
caller!o();
caller!({ writeln("Function literal called."); })();
```
Converted this to source/app.d
```
import std.stdio;
void main() {
auto o = new C();
caller!o();
caller!({ writeln("Function literal called."); })();
}
class C {
void opCall() {
writeln("C.opCall called.");
}
}
```
Compiled with DMD yielding error messages:
```
c:\dev\D\71 -
80\c78_3k_alias_template_opCall_overload\source\app.d(5): Error:
template instance `caller!o` template `caller` is not defined
caller!o();
^
c:\dev\D\71 -
80\c78_3k_alias_template_opCall_overload\source\app.d(7): Error:
template instance `caller!(()
{
writeln("Function literal called.");
}
)` template `caller` is not defined
caller!({ writeln("Function literal called."); })();
^
```
What is needed to get this code to compile?
My only idea is that a #import statement is missing.
More information about the Digitalmars-d-learn
mailing list