intended c++ virtual function not getting called -
this code
#include "stdafx.h"** class iplayback { public: virtual void createrenderstream() = 0; }; class icapture { public: virtual void createcapturestream() = 0; }; class iaudiostackinterface { public: virtual void createstream() = 0; }; class caudioclientinterface : public iaudiostackinterface, public icapture, public iplayback { void createcapturestream() { printf("\n in createcapturestream"); } void createrenderstream() { printf("\n in createrenderstream"); } void createstream() { printf("\n in createstream"); } }; typedef iaudiostackinterface* piaudiostackinterface; typedef icapture* pcapture; typedef iplayback* piplayback; typedef void* pvoid; int main() { pvoid pobj = new caudioclientinterface(); piplayback pplaybackinterfcace = (piplayback) pobj; pplaybackinterfcace->createrenderstream(); return 0; }
i should createrenderstream printed whereas getting createstream printed?
try
piplayback pplaybackinterfcace = (piplayback)(caudioclientinterface*) pobj;
you allowed cast void*
, original type caudioclientinterface*
. casting type undefined behavior.
Comments
Post a Comment