How to initialize const member requiring computations to be performed?

Use a function call inside a delegating (if avaliable, not neccessarily) constructor’s member initialization list:

A::A(std::string const& yourstring) : A(compute_myint(yourstring)) {};

Pass std::string by const&, not just const, while you’re at it.

compute_myint can be non-member, static member, possibly not accessible from outside the class, whichever makes the most sense.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)