The order of member initialization is the same with the order they appear in the class definition. Since rem
appears first, it will be initialized first. But the value of base
is undefined when rem
is initialized, thus the value of rem
is undefined. To fix the problem, we can either switch the order of definitions of rem
and base
or we can use the constructor parameters i
and j
direct initialize rem(i % j)
.