Pointer on templated class

M

mosfet

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>::preTranslateMessage(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 ?
 
S

Salt_Peter

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>::preTranslateMessage(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?
 
N

Noah Roberts

mosfet said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,529
Members
48,242
Latest member
BarbMott55

Latest Threads

Top