CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    C-style cast suceeds whereas static_cast reports error

    I am using Visual Studio 2005:

    The following code fails:

    Code:
    using namespace NepwareGames::MainApplication;
    
    CApplicationCallback *pWin = static_cast<CApplicationCallback *>(new CWindow);
    The error reported is

    Code:
    1>j:\nepwaregames\nepwaregames\nepwaregames.cpp(28) : error C2243: 'static_cast' : conversion from 'NepwareGames::MainApplication::CWindow *' to 'NepwareGames::MainApplication::CApplicationCallback *' exists, but is inaccessible
    However the C-style cast works fine and the program executes as expected.

    The following are the declaration of the classes:

    Code:
    namespace NepwareGames
    {
    	namespace MainApplication
    	{
    		class CApplicationCallback
    		{
    		public:
    			// pure virtual functions
    			virtual ~CApplicationCallback(void)= 0 {}
    			virtual bool CreateEx(DWORD dwExStyle, LPCTSTR lpszClass, LPCTSTR lpszName, DWORD dwStyle,
    									int x, int y, int nWidth, int nHeight, HWND hParent,
    									HMENU hMenu, HINSTANCE hInst) = 0;
    			virtual WPARAM MessageLoop(void) = 0;
    			virtual BOOL ShowWindow(int nCmdShow) const = 0;
    			virtual BOOL UpdateWindow(void) const = 0;
    		};
    
    		class CApplication
    		{
    		public:
    			static CApplication * Create (CApplicationCallback *par);
    		};
    	}
    }
    Code:
    namespace NepwareGames
    {
    	namespace MainApplication
    	{
    		class CWindow : CApplicationCallback
    		{
    		private:
    			CApplication *m_CApplication;
    		private:
    			virtual void OnDraw(HDC hDC){}
    			virtual void OnKeyDown(WPARAM wParam, LPARAM lParam);
    			virtual LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    			static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    			virtual void GetWndClassEx(WNDCLASSEX & wc);
    		public:
    			HWND  m_hWnd;
    
    			CWindow(void) : m_hWnd(NULL) {}
    			~CWindow(void) {}
    			virtual bool CreateEx(DWORD dwExStyle, LPCTSTR lpszClass, LPCTSTR lpszName, DWORD dwStyle,
    									int x, int y, int nWidth, int nHeight, HWND hParent,
    									HMENU hMenu, HINSTANCE hInst);
    			bool RegisterClass(LPCTSTR lpszClass, HINSTANCE hInst);
    			virtual WPARAM MessageLoop(void);
    			virtual BOOL ShowWindow(int nCmdShow) const
    			{
    				return ::ShowWindow(m_hWnd, nCmdShow);
    			}
    			virtual BOOL UpdateWindow(void) const
    			{
    				return ::UpdateWindow(m_hWnd);
    			}
    		};
    	}
    }
    Please help
    Last edited by miteshpandey; February 3rd, 2008 at 06:27 AM.
    If there is no love sun won't shine

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured