Use the "friend" keyword to let the CW1Dlg class and the other class communicate.
Alternatively you could make lastTime global, it will work, but normally I try to avoid this...
Main Topics
Browse All Topicswin32, Visual C++6 , beginner (i mean real beginner :)
Sorry for this question but i really dont know. I am getting the time in one class and i am trying to access it in another class. But how do i do that ?
void CW1Dlg::SetData(float* newnndata, float* newppdata)
{
chart3.SetData(newnndata);
chart2.SetData(newppdata);
CTime lastTime;
lastTime = CTime::GetCurrentTime();
}
now i would like to access lastTime elsewhere. For example in another class
CTimeSpan MinutesX15 = CTimeSpan(0,0,1,0);
CString display_time;
CTimeSpan Minutesmin15 = CTimeSpan(0,0,15,0);
lastTime -= Minutesmin15;
like this.
Can you give me some tips with sharing information in a program. I know its really basic but it would help me understand.
thanks...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Declare one more member function in CW1Dlg class as
public:
CTimeSpan GetLastTime();
void SetLastTime(CTimeSpan cTime);
then define as given below
CTimeSpan CW1Dlg::GetLastTime()
{
return lastTime;
}
void CW1Dlg::SetLastTime(CTimeS
{
lastTime = cTime;
}
To get/read the Last time use
CW1Dlg cW1DlgTemp;
CTimeSpan dtTempTime = cW1DlgTemp.GetLastTime();
To Set/Update the Last time use
CTimeSpan MinutesX15 = CTimeSpan(0,0,1,0);
CTimeSpan Minutesmin15 = CTimeSpan(0,0,15,0);
CTimeSpan dtTempTime = cW1DlgTemp.GetLastTime();
dtTempTime -= Minutesmin15;
cW1DlgTemp.SetLastTime(dtT
Try this
All the Best
-Vasudev
Hi,
Vasu: Ur solution may work but is not exactly the right way to implement.
I think forza is right. Since peter has 2 different classes it is better to go by the "friend" approach. His alternate approach though should be avoided.
Another alternative: again not the best but easy is:
Have a static member variable in CW1Dlg say m_stcTime and 2 member functions CW1Dlg::SetTime(..) and CW1Dlg::GetTime(..)
..
To set time call SetTime() and to get it anywhere call GetTime.
The limitation is that only one time can exist at any time. For example if there is a CW1Dlg dlg1 and dlg2, and both try to do set get the time the whole thing will definately be a mess. It is good if and only if one and only one instance of CW1Dlg class exists.
Hope this helps,
All the best,
bye
BYW: Is ch_vasu from Kshema Tech, Blr????
Bye
Abdij
"Have a static member variable in CW1Dlg say m_stcTime and 2 member functions CW1Dlg::SetTime(..) and CW1Dlg::GetTime(..) "
could you write down an example please. I come from Java. Beginner there too and i really dont understand the syntax of those ::
i am adjusting the points for some extra lesson if you dont mind ?
thanks...
If you have a class with all kinds of functions in it. You have to somehow fill in the functions (what they should do), thus you write out the functions like
void GetTime(void)
{
...
}
but how will the compiler know that it belongs to that certain class? It knows by using the double :
First you write the returntype, then the class and then you write the function name.
CJ
Hi Peter,
Could u pl. explain more on the context of usage of your variable 'lastTime'. Because the implementation depends upon the life time of the object and the security of data.
1. If the variable is used to store the Last time of any object of CW1Dlg then you can make use of getTime() and setTime(). But if each object of the class has its own lastdate (usaully)storage then the static usage will be wrong.
2. The usage the friend function almost voilates the O.O.Concept. Before using friend function think twise whether that context suggests that?. (i am worried about the security of lastTime)
Ans1:
if you need only static variable m_stcTime you need not have to have member function to use it. U can
1) Get the Last Date by
CTimeSpan dtTempTime = CW1Dlg::m_stcTime and
2) Set the Last Date by CW1Dlg::m_stcTime = dtTempTime and
Ans2:
if you need static variable and 2 static member functions then,
Example:
Declare members in CW1Dlg class as
public:
static m_stcTime;
static CTimeSpan GetLastTime();
static void SetLastTime(CTimeSpan cTime);
rest of the code remains same as commented lasttime.
Try this out
bye
-Vasudev
Business Accounts
Answer for Membership
by: CJ_SPosted on 2000-05-05 at 01:22:14ID: 2779883
How about having one function in the CW1Dlg which returns you the address of lastTime. Then you send that address to the other class which then can use that address. Only a few changes have to be made (ie, pointers and references), but you can do that on your own.