You need to tell the compiler which of the two 'Base' types you
want created. You need to say
return Derived1::Base();
or
return Derived2::Base();
Alternatively, you can make 'Base' a virtual base class if you
define *both* Derived1 and Derived2 as
class Derived1 : public virtual Base
class Derived2 : public virtual Base
in which case 'Derived' will have only one subobject of type Base
in it. Read up on virtual inheritance.
int main(int argc,char *argv[])
{
Derived d;
printf("------------------\n");
d.make2();
printf("------------------\n");
return 0;
}
cl -W4 -nologo /J aa.cpp user32.lib
when i comment out the ":public Base" at "Derived2" then the code
compiles and the result is :
0012FF70 : 12 : 0
0012FF70 : 29 : 1
0012FF74 : 47 : 2
0012FF70 : 66 : 3
------------------
0012FF6C : 12 : 4
------------------
so, as expected, Derived::Derived1::Base has nothing to do with the
call to Base(), Base() creates a new item.
I don't understand that statement, sorry.
He means that his make2() method returns a new Base object; it is not returning
*this.
error either.