C++:我可以在调用另一个构造函数之前进行一些处理吗?

Ele*_*Ent 2 c++ constructor c++11 delegating-constructor

我有一个有两个构造函数的类.

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

  Foo(int n) : Foo(buildBFromInt(n)) {} ??
}
Run Code Online (Sandbox Code Playgroud)

第一个需要一些对象,我想要第二个首先从更简单的类型创建对象.这可能吗 ?

Jar*_*d42 8

从C++ 11开始就有可能.它是委托构造函数,您使用正确的语法.