473,398 Members | 2,120 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,398 software developers and data experts.

inner class

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[i].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 ?






Nov 9 '07 #1
1 1448
mosfet wrote:
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[i].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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Murat Tasan | last post by:
i have an inner class and an outer class, both of which have an identically named member. how from the inner class can i reference the outer member? (the example code should illustrate this...
1
by: Murat Tasan | last post by:
hi, i am having a small problem with constructing an inner class. i am using an inner class (and not a static nested class) because the methods of the inner class need access to the enclosing...
5
by: devu | last post by:
Currently I'm working on a class that performs a batch process as per scheduling for all employees in a company. Being a batch process load is obviously a huge factor. The process first needs to...
10
by: Paul Morrow | last post by:
I'm hoping that someone can explain why I get the following exception. When I execute the code... ###################################### class Parent(object): class Foo(object): baz = 'hello...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
9
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added...
4
by: amaca | last post by:
In this slightly contrived (though small, complete and perfectly formed) example: public class Inner { public event EventHandler InnerHandler; public void DoSomething() { if ( InnerHandler...
5
by: Martijn Mulder | last post by:
A construction like this: class Outer { class Inner:Outer { } } compiles without problem but does it introduce infinity?
1
by: mrstephengross | last post by:
I'm making progress on mixing templates with friends (sounds like a drinking game, huh?). Anyway, here's the situation. I've got an "Outer" class with a private "Inner" class (sub-class,...
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.