+ Reply to Thread
Results 1 to 2 of 2

Thread: What is warning C4243 in VC++?

  1. #1

    What is warning C4243 in VC++?

    What is warning C4243: type cast conversion from 'class CDerive *' to 'class CBase *' exists, but is inaccessible

    Following code:

    Code:
    class CBase
    {
    public:
    	virtual int GetData() = 0 ;
    } ;
    
    class CDerive : private CBase
    {
    public:
    	virtual int GetData()
    	{
    		return 42 ;
    	}
    } ;
    
    void UseInheritance()
    {
    	CDerive *pDerived = new CDerive() ;
    
    	int nData = pDerived->GetData() ;
    
    	CBase *pBase = (CBase *) pDerived ;
    
    	nData = pBase->GetData() ;
    }
    What could be the cause of the issue?

  2. #2
    It seems that you used 'private' inheritance rather than 'public'

    Code:
    class CBase
    {
    public:
    	virtual int GetData() = 0 ;
    } ;
    
    class CDerive : public CBase //note here we used 'public' instead of 'private'
    {
    public:
    	virtual int GetData()
    	{
    		return 42 ;
    	}
    } ;
    
    void UseInheritance()
    {
    	CDerive *pDerived = new CDerive() ;
    
    	int nData = pDerived->GetData() ;
    
    	CBase *pBase = (CBase *) pDerived ;
    
    	nData = pBase->GetData() ;
    }
    Is this the case for you?

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts