C++
#include <stdio.h>
class a
{
public:
int var1;
a(int var)
{
var1 = var;
printf("set var1 to %d\n", var1);
}
};
class b: public a
{
public:
int var2;
b(int d) : var2(d++), a(var2++)
{
printf("d: %d, var2: %d, var1: %d\n", d, var2, var1);
}
};
int main()
{
int a = 5;
b obj1(a);
printf("%d\n", obj1.var1);
}
输出:
set var1 to 0
d: 6, var2: 5, var1: 0
0
[Finished in 0.7s]
为什么这里a.var1
不设置为6?