0

Assuming that we have:

class A ...
class B inherit A ...

f (a_a: A) ...

Then, can you write something like the following pseudocode, without using a temporary variable?

-- `y` is an argument to B's constructor.
f (create B.make(y))
Eleno
  • 2,864
  • 3
  • 33
  • 39

1 Answers1

2

You are looking for a creation expression. Unlike creation instruction, it omits target entity, but always specifies a creation type:

create {B}.make (y)

Note. As a rule of thumb, if a type can be confused with an entity, it is enclosed in curly braces. For example, in the phrase create B.make (y) the terminal B is interpreted as an entity name. Enclosing it in the braces promotes it to a type.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35