Click here to Skip to main content
15,890,579 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to design multiple inheritance classes? Pin
Christian Graus27-Jul-05 18:08
protectorChristian Graus27-Jul-05 18:08 
GeneralRe: how to design multiple inheritance classes? Pin
nm_11427-Jul-05 18:34
nm_11427-Jul-05 18:34 
GeneralRe: how to design multiple inheritance classes? Pin
Christian Graus27-Jul-05 19:06
protectorChristian Graus27-Jul-05 19:06 
GeneralRe: how to design multiple inheritance classes? Pin
nm_11427-Jul-05 19:56
nm_11427-Jul-05 19:56 
GeneralRe: how to design multiple inheritance classes? Pin
GDavy27-Jul-05 20:29
GDavy27-Jul-05 20:29 
GeneralRe: how to design multiple inheritance classes? Pin
nm_11428-Jul-05 18:02
nm_11428-Jul-05 18:02 
GeneralRe: how to design multiple inheritance classes? Pin
vikramlinux27-Jul-05 20:39
vikramlinux27-Jul-05 20:39 
GeneralRe: how to design multiple inheritance classes? Pin
Bob Stanneveld27-Jul-05 21:21
Bob Stanneveld27-Jul-05 21:21 
Hello,

As some other user already suggested, you should use virtual base classes (if you want to share among the different types). See Here[^] for more information on virtual inheritance.

Another way to go (IMHO the better way) is to encapsulate some details of your base classes using private inheritance instead of public. Also you need to override some other functions to resolve the ambiguities:
struct WFIOInfo
{	HANDLE m_hFile;	
	DWORD m_dwBytes;
};

class WinFileInInterface
{
public:	
	virtual BOOL Open(LPCTSTR lpszFileName);	
	virtual BOOL DoReadFile(LPVOID lpBuffer, DWORD nNumberOfBytesToRead);
};

class WinFileOutInterface
{
public:	
	virtual BOOL Open(LPCTSTR lpszFileName);	
	virtual BOOL DoWriteFile(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite);
};

class CWinFileIn : private WFIOInfo, public WinFileInInterface
{
public:	
	virtual BOOL Open(LPCTSTR lpszFileName)	
	{return TRUE;}	
	virtual BOOL DoReadFile(LPVOID lpBuffer, DWORD nNumberOfBytesToRead)	
	{return ::ReadFile(m_hFile, lpBuffer, nNumberOfBytesToRead, &m_dwBytes, NULL);}
};

class CWinFileOut : private WFIOInfo, WinFileOutInterface
{
public:	
	virtual BOOL Open(LPCTSTR lpszFileName)	{return TRUE;}	
	virtual BOOL DoWriteFile(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite)
	{return ::WriteFile(m_hFile, lpBuffer, nNumberOfBytesToWrite, &m_dwBytes, NULL);}
};

class CWinFileInOut : private: WFIOInfo, 
		      public: WinFileInInterface, 
  		      public: WinFileOutInterface
{
public:	
	BOOL Open(LPCTSTR lpszFileName)	
	{	return TRUE;	}
};


Using the private inheritance, you make the class only visible and accessible to the class that derives from it. Classes which are derived from that class, do not know about the previous privatly inherited classes. This way, you can have multiple names inside different classes.

Hope this helps Big Grin | :-D

Behind every great black man...
            ... is the police. - Conspiracy brother


Blog[^]
GeneralRe: how to design multiple inheritance classes? Pin
nm_11429-Jul-05 11:24
nm_11429-Jul-05 11:24 
GeneralRe: how to design multiple inheritance classes? Pin
Christian Graus31-Jul-05 13:23
protectorChristian Graus31-Jul-05 13:23 
GeneralRe: how to design multiple inheritance classes? Pin
nm_11431-Jul-05 19:42
nm_11431-Jul-05 19:42 
GeneralRe: how to design multiple inheritance classes? Pin
Christian Graus31-Jul-05 19:45
protectorChristian Graus31-Jul-05 19:45 
GeneralRe: how to design multiple inheritance classes? Pin
sunit527-Jul-05 19:53
sunit527-Jul-05 19:53 
AnswerRe: how to design multiple inheritance classes? Pin
Tim Smith27-Jul-05 17:07
Tim Smith27-Jul-05 17:07 
Generalquestion about tab control Pin
firebolt7727-Jul-05 16:33
firebolt7727-Jul-05 16:33 
GeneralRe: question about tab control Pin
Christian Graus27-Jul-05 16:50
protectorChristian Graus27-Jul-05 16:50 
GeneralRe: question about tab control Pin
firebolt7727-Jul-05 17:00
firebolt7727-Jul-05 17:00 
GeneralRe: question about tab control Pin
Christian Graus27-Jul-05 17:04
protectorChristian Graus27-Jul-05 17:04 
GeneralRe: question about tab control Pin
firebolt7727-Jul-05 17:15
firebolt7727-Jul-05 17:15 
GeneralRe: question about tab control Pin
Christian Graus27-Jul-05 17:24
protectorChristian Graus27-Jul-05 17:24 
GeneralSearching for help on-line Pin
onlysaint27-Jul-05 15:14
onlysaint27-Jul-05 15:14 
GeneralRe: Searching for help on-line Pin
koothkeeper27-Jul-05 16:10
professionalkoothkeeper27-Jul-05 16:10 
GeneralJOB_INFO_2 Time member not set Pin
koothkeeper27-Jul-05 14:15
professionalkoothkeeper27-Jul-05 14:15 
GeneralRe: JOB_INFO_2 Time member not set Pin
Graham Bradshaw27-Jul-05 15:04
Graham Bradshaw27-Jul-05 15:04 
GeneralRe: JOB_INFO_2 Time member not set Pin
koothkeeper27-Jul-05 16:03
professionalkoothkeeper27-Jul-05 16:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.