我正在玩构造/破坏对象.这是我尝试过的http://coliru.stacked-crooked.com/a/ff17cc5649897430:
#include <iostream>
struct B{
B(){ std::cout << "B()" << std::endl; }
B(int){ std::cout << "B(int)" << std::endl; }
};
struct A : virtual B
{
int B;
A(int a) : B(a) { std::cout << "A(int)" << std::endl; }
} a(10);
int main()
{
}
Run Code Online (Sandbox Code Playgroud)
程序输出是
B()
A(int)
Run Code Online (Sandbox Code Playgroud)
为什么?我明确指定了B要在ctor-initializer中调用的类的构造函数.
| 归档时间: |
|
| 查看次数: |
27 次 |
| 最近记录: |