miteshpandey
February 3rd, 2008, 05:17 AM
I am using Visual Studio 2005:
The following code fails:
using namespace NepwareGames::MainApplication;
CApplicationCallback *pWin = static_cast<CApplicationCallback *>(new CWindow);
The error reported is
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:
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);
};
}
}
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
The following code fails:
using namespace NepwareGames::MainApplication;
CApplicationCallback *pWin = static_cast<CApplicationCallback *>(new CWindow);
The error reported is
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:
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);
};
}
}
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