inner class

M

mosfet

Hi,

here is my problem. I have a base class and two class deriving from it
that I use to handle different UI context.
These classes are used inside another UI class called CMainView

// definition
class UIContext
{
public:
UIContext(CMainView* pView, LPListInfo_t lpListInfo = NULL) = 0;
virtual ~UIContext();

virtual void DoLayout() = 0;
virtual void SetListView() = 0;
virtual LPListInfo_t GetListInfo();

protected:

LPListInfo_t m_lpListInfo;
int m_nItemCount;
CMainView* m_pView;
};


class UIContextMain : public UIContext
{
public:
UIContextMain( CMainView* pView );
virtual ~UIContextMain() {}

virtual void DoLayout();
virtual void SetListView();
};

class UIContextSettings : public UIContext
{
public:
UIContextSettings( CMainView* pView );
virtual ~UIContextSettings() {}

virtual void DoLayout();
virtual void SetListView();
};

class CMainView : public CBaseView
{

....
protected:
UIContext* m_pCurCtx; // Current context
UIContextMain* m_pCtxMain; // Main Context
UIContextSchedule* m_pCtxSchedule; // Scheduling context
UIContextSettings* m_pCtxSettings; // Settings Context
}

----------------------------------------------------------------
Implemntation:

UIContext::UIContext(CMainView* pView, LPListInfo_t lpListInfo)
{
m_pView = pView;
m_lpListInfo = NULL;
}


void UIContextMain::SetListView()
{
CString strText;
CSyncClient* pSyncClient = CSyncClient::GetInstance();

int nIndex = 0;
for (int i = 0; i < m_nItemCount ; i++)
{
strText = m_pView->GetResText(m_lpListInfo.TextId);
...
}
}


The problem with this approach is that I need to use m_pView everytime I
need to access to my CMainView*.
How can I have a class that can directly access to CMainView members
without having to deference a pointer ?
 
V

Victor Bazarov

mosfet said:
here is my problem. I have a base class and two class deriving from it
that I use to handle different UI context.
These classes are used inside another UI class called CMainView

// definition
class UIContext
{
public:
UIContext(CMainView* pView, LPListInfo_t lpListInfo = NULL) = 0;
virtual ~UIContext();

virtual void DoLayout() = 0;
virtual void SetListView() = 0;
virtual LPListInfo_t GetListInfo();

protected:

LPListInfo_t m_lpListInfo;
int m_nItemCount;
CMainView* m_pView;
};


class UIContextMain : public UIContext
{
public:
UIContextMain( CMainView* pView );
virtual ~UIContextMain() {}

virtual void DoLayout();
virtual void SetListView();
};

class UIContextSettings : public UIContext
{
public:
UIContextSettings( CMainView* pView );
virtual ~UIContextSettings() {}

virtual void DoLayout();
virtual void SetListView();
};

class CMainView : public CBaseView
{

...
protected:
UIContext* m_pCurCtx; // Current context
UIContextMain* m_pCtxMain; // Main Context
UIContextSchedule* m_pCtxSchedule; // Scheduling context
UIContextSettings* m_pCtxSettings; // Settings Context
}

----------------------------------------------------------------
Implemntation:

UIContext::UIContext(CMainView* pView, LPListInfo_t lpListInfo)
{
m_pView = pView;
m_lpListInfo = NULL;

A BAD IDEA(tm). Do not use assignment, use initialisation.
}


void UIContextMain::SetListView()
{
CString strText;
CSyncClient* pSyncClient = CSyncClient::GetInstance();

int nIndex = 0;
for (int i = 0; i < m_nItemCount ; i++)
{
strText = m_pView->GetResText(m_lpListInfo.TextId);
...
}
}


The problem with this approach is that I need to use m_pView
everytime I need to access to my CMainView*.


Uh... Yes. How else do you think of accessing it? And what _is_
the problem with using 'm_pView' to access that object?
How can I have a class that can directly access to CMainView members
without having to deference a pointer ?

What would the interface look like? What do you expect that class to
do? How would you call its member functions, and what are they going
to be named?

V
 

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
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top