# Include "stdafx. H"
# Include <assert. h>
Class iinterface1
{
Public:
Virtual void vfunc1 () = 0;
};
Class iinterface2
{
Public:
Virtual void vfunc2 () = 0;
};
Class testclass1:
Public iinterface1, public iinterface2
{
Void vfunc1 ();
Void vfunc2 ();
};
Void testclass1: vfunc1 ()
{
;
}
Void testclass1: vfunc2 ()
{
;
}
Class interface12:
Public iinterface1, public iinterface2
{
};
Template <class intttt>
Intttt * makeinterface2 (iinterface1 * pinterface1)
{
Return static_cast <intttt *> (static_cast <interface12> (pinterface1 ));
}
Int _ tmain (INT argc, _ tchar * argv [])
{
Testclass1 * ptestclass1 = new testclass1 ();
Iinterface1 * pinterface1 = dynamic_cast <iinterface1 *> (ptestclass1 );
Assert (pinterface1 );
Iinterface2 * pinterface2 = static_cast <iinterface2 *> (pinterface1 );
Iinterface2 * pinterface2 = makeinterface2 <iinterface2> (pinterface1 );
Return 0;
}
The red line code will cause compile error:
Error c2440: 'static _ cast': cannot convert from 'iinterface1 * 'to 'iinterface2 *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast