473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pointer on templated class

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
2 1684
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
2
by: Chris Schadl | last post by:
Hi, I'm working on writing a templated Binary Search Tree class in C++. In regular C, I would have functions which traverse the tree take a pointer to a user-defined function as an argument,...
1
by: FP | last post by:
I have a function that returns a base class pointer as in: baseClass<T>* FunctionA( ); As you can see the baseClass is templated. FunctionA is found in a third templated class. What I'm...
15
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here...
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
2
by: Anonymous | last post by:
template<class T> class A { public: A() { T * object = new T(this); //passing instance as parent of nested class m_obj.push_back(object); } ~A() {
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.