C++ : can I do some processing before calling another constructor?

248 Views Asked by At

I have a class with two constructors.

class Foo {
  Foo(B b) {... }

  Foo(int n) : Foo(buildBFromInt(n)) {} ??
}

The first takes some object and I would like to have a second one that first creates the object from a simpler type. Is this possible ?

1

There are 1 best solutions below

1
Jarod42 On BEST ANSWER

It is possible since C++11. it is the delegating constructor, and you use the correct syntax.