multiple inheritance cast in c++ -


i have issue concerning multiple inheritance cast. have 3 base classes

class readfile; class writefile class sharedobject; // class mutex 

based on class build:

class readwritefile : public readfile, public writefile { ... };  class readwritesharedfile : public readwritefile , public sharedobject { ... };  class readfileshared : public readfile, public sharedobject { ... }; 

at point of code, have readwritesharedfile pointer cast pointer readfileshared

readfileshared * l_data = dynamic_cast<readfileshared * >(m_data); // m_data readwritesharedfile  

it compiles @ execution, cast "fails" , l_data null

however, want achieve sounds legit me. it? doing wrong. thanks

readfileshared , readwritesharedfile unrelated classes, although inherit same base classes. therefore, cannot cast reference/pointer 1 another.

your functions should use interfaces readfile , writefile, rather require particular implementation of them. main idea behind interfaces. see c++ interface classes - introduction more details.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -