ElefEnt
ElefEnt

Reputation: 2127

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

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 ?

Upvotes: 2

Views: 256

Answers (1)

Jarod42
Jarod42

Reputation: 217438

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

Upvotes: 8

Related Questions