By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

Pointer on templated class

P: n/a
Hi,

I have qome questions about templated class and pointer.
Let's says I have some graphical classes defined like this(WTL framework) :

// represent a view
class CFooView : public CStdDialogImpl<CFooView>
{
public:
enum { IDD = IDD_FOO_FORM };

....
};

// represent a welcome view
class CWelcomeView : public CStdDialogImpl<CWelcomeView>
{
public:
....

};

class CMainFrame :
public CFrameWindowImpl<CMainFrame>,
public CUpdateUI<CMainFrame>,
public CAppWindow<CMainFrame>,
public CFullScreenFrame<CMainFrame>,
public CMessageFilter,
public CIdleHandler,
public CMDIBase<CMainFrame>
{
public:
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessa ge(pMsg))
return TRUE;

return m_mainView.IsWindow() ? m_mainView.PreTranslateMessage(pMsg) :
FALSE;
}
// our views
CVoxsyncBackupView m_mainView;
CWelcomeView m_welcomeView;
???????????? m_curView;
....
};

As you can see in CMainFrame class I have some views defined in it and I
am supposed to be able to switch between them.
The problem comes from the PreTranslateMessage method, because it is
supposed to point to the current view.

So how could I declare a kind of pointer on the current templated class ?
Until now I was using only one view so PreTranslateMessage is using
m_mainView but what if I want to use another view ?



May 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 2, 7:46 am, mosfet <john....@anonymous.orgwrote:
Hi,

I have qome questions about templated class and pointer.
Let's says I have some graphical classes defined like this(WTL framework) :

// represent a view
class CFooView : public CStdDialogImpl<CFooView>
{
public:
enum { IDD = IDD_FOO_FORM };

...

};

// represent a welcome view
class CWelcomeView : public CStdDialogImpl<CWelcomeView>
{
public:
...

};

class CMainFrame :
public CFrameWindowImpl<CMainFrame>,
public CUpdateUI<CMainFrame>,
public CAppWindow<CMainFrame>,
public CFullScreenFrame<CMainFrame>,
public CMessageFilter,
public CIdleHandler,
public CMDIBase<CMainFrame>
{
public:

virtual BOOL PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessa ge(pMsg))
return TRUE;

return m_mainView.IsWindow() ? m_mainView.PreTranslateMessage(pMsg) :
FALSE;

}

// our views
CVoxsyncBackupView m_mainView;
CWelcomeView m_welcomeView;
???????????? m_curView;

...

};

As you can see in CMainFrame class I have some views defined in it and I
am supposed to be able to switch between them.
The problem comes from the PreTranslateMessage method, because it is
supposed to point to the current view.

So how could I declare a kind of pointer on the current templated class ?
Until now I was using only one view so PreTranslateMessage is using
m_mainView but what if I want to use another view ?
probably:
CWnd * pView;

However, this has nothing to do with C++. Why not try in a relevant
newsgroup?

May 2 '07 #2

P: n/a
mosfet wrote:
As you can see in CMainFrame class I have some views defined in it and I
am supposed to be able to switch between them.
You can't.
The problem comes from the PreTranslateMessage method, because it is
supposed to point to the current view.

So how could I declare a kind of pointer on the current templated class ?
Until now I was using only one view so PreTranslateMessage is using
m_mainView but what if I want to use another view ?
Two ways.

I ran into this issue myself and switched to runtime based dialog
detection. Instead of IDD being an enum it becomes a variable and the
base class a non-template. So there is way number one.

Number two involves studying boost::any and realizing that kind of idiom
can be used to virtualify any interface.

There are probably others but that's my ideas.
May 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.