F
F
floppa3222021-12-09 21:20:59
C++ / C#
floppa322, 2021-12-09 21:20:59

Statements inside constructor initialization list?

Is there a way to write multiple staments in the constructor's initialization list?

class Example
{
private:
    ExtremelyHeavyObject obj;

public:
    
    Example(): 
    obj
    (
        ExtremelyHeavyObjectBuilder builder;    
        builder.method1();
        builder.method2();
        builder.method3();
        /* Some code here */
        return builder.build(); // Assign to obj builder.build() result
    )
    {}
};


I would not like to consider using ExtremelyHeavyObject obj *it, since it would require additional. allocations/de-allocations as well as an extra direct

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question