为什么我得到一个输出"b(1) dc dvfunc"?
why I got an output 'b(1) dc dvfunc'?
我在这里的预期输出是"bc bvfunc b(1(dc dvfunc",但我得到了像"b(1?有人能帮我吗?谢谢你宝贵的时间!
#include<iostream>
using namespace std;
class b {
public:
b() {
cout<<" bc ";
b::vfunc();
}
virtual void vfunc(){ cout<<" bvfunc "; }
b(int i){ cout<<" b(1) "; }
};
class d : public b {
public:
d(): b(1) {
cout<<" dc ";
d::vfunc();
}
void vfunc(){ cout<<" dvfunc"; }
};
main()
{
d d;
}
要获得所需的输出,您需要
d(){b(1); //move b(1) from initializer list and put it in a constructor.
cout<<" dc ";
FYI initializer list
用于在构造函数调用默认值之前initialize
类的成员。构造函数可以覆盖这些值。
做事的顺序:
d((被调用。这将调用b(1(,然后调用构造函数的其余部分。
所以呼叫顺序是
b(1)
d() -> which is cout fc, and then cout dvfunc
b((从未被调用,因此它不会到达bvfunc。b((和b(int i(都是独立的构造函数,并且只调用其中一个,而不是两者。
相关文章:
- 使用 fftw 的图像中间的 DC 组件
- HBITMAP 上的 DrawText 没有 "visible" DC?
- 启动时不显示 Direct2D DC 上下文呈现的图像
- 图形没有显示何时使用IDXGISURFACE1使用的GDI兼容DC
- 用于 2 辆 DC 汽车的 arduino IDE 代码,带有 L298 和超声波和蓝牙控制与安卓
- 为什么释放DC()
- 使用 MFC 打印到打印机 DC
- 用于C/C++的MC/DC覆盖工具
- 无论使用内存DC和BitBlit,GDI中都会闪烁
- CClientDC 和 DC 不在 ChtmlEditCtrl 上绘制
- 图片从DC到Word文档
- 选择内存 DC 上的对象
- 如何将此类位图复制到 DC
- 内存中的 GDI+ DC 始终为单色
- 我在wxPaint DC绘图中发现了一件奇怪的事情
- 如何让Nsight EE使用-dc标志进行编译
- BitBlt与从打印机DC创建的内存DC有关
- Handle of DC C++ Windows
- GDI+只在内存DC上绘制单色
- 为什么我得到一个输出"b(1) dc dvfunc"?