|
Hello everyone,
Here is Bjarne's exception safe sample,
http://www.research.att.com/~bs/3rd_safe.pdf
template <class t=""> class Safe {
T* p ;
public :
Safe () : p (new T ) { }
˜Safe () { delete p ; }
Safe& operator =(const Safe&a) { *p = *a .p ; return *this; }
};
template <class t=""> class Unsafe {
T* p ;
public :
Unsafe (T* pp ) : p (pp ) { }
˜Unsafe () { if (!p->destructible ()) throw E(); delete p; }
Unsafe& operator =(const Unsafe&a)
{
p->˜T ();
new(p)T (a.p );
return *this;
}
};
</class></class>
What makes me confused is, the description about why it is not exception safe,
--------------------
The assignment operator may fail by throwing an exception from T ’s copy constructor. This would
leave a T in an undefined state because the old value of *p was destroyed and no new value
replaced it.
--------------------
In my study, I can not find a case why there is exception thrown from Unsafe's copy constructor. Any ideas?
BTW: it is also appreciated if you could share some experiences about what in your minds does invariant status mean
(in Bjarne's minds, exception safety means making the object into invariant status). I find the word *invariant* is
somethings hard to understand.
thanks in advance,
George
modified on Monday, December 24, 2007 3:02:32 AM
|
|
|
|
|
Hey George, please reformat your post (it is a difficult question even with well formatted one!).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Thanks CPallini,
I have re-formatted it. Is that ok now?
regards,
George
|
|
|
|
|
Uhm, no George, unless the tongue sticking out of the faces is intentional.
Insert a blank between : and p in you code, otherwise you'll get :p.
Have a nice day.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Thanks CPallini,
I have followed your advice, cool! Do you think the format is ok now?
regards,
George
|
|
|
|
|
OK, now let's move to the question:
I think that the copy constructor can fail because it relies on the assignment operator
that in turn, relies on T copy constructor.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Thanks CPallini,
I do not know why T's copy constructor can throw an exception. In what situation will it throw an exception?
regards,
George
|
|
|
|
|
Well, I haven't the book, so I take it as a hypothesis. If you have it, you can further investigate reading §10.4.11 .
The author also points out that allocation may fail.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Maybe placement operator new will throw some exceptions? I do not know. It is appreciated if you or other people could give some insight.
regards,
George
|
|
|
|
|
|
Do you have a question in all of that gibberish somewheres?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello there ,
I want to get handle of specific application before start ,but i don't know how can i get that message and process it . in fact , i don't know exactly which message , i must be process .
Thank you .
DMASTER
|
|
|
|
|
I think for get a handle to a program you need to run it.
|
|
|
|
|
Dear Hamid, thanks to your reply.
But, my question is that, when ever the user runs an application, how can i make a notification of that process start, in my own application.
In fact, i want to query the process-start! I wonder if any system message (or any other method) exists, when an application starts?!
DMASTER
|
|
|
|
|
If you know name of program you can use of FindWindow but if you dont know name of program you can use of EnumDesktopWindows for Enumerates all windows or EnumWindows for enumerates all windows on the screen that it gives you a handle to each window.
|
|
|
|
|
I know these functions and their usage! but as you know, I should use them AFTER the process is already ran, and (for example) i should use them on the click of a button!
the problem is that, my application should be aware of the process start, AS SOON AS THE PROCESS STARTS, and do its job automatically. I'm looking for a method, to make my application aware of the start event FOR ALL THE APPLICATIONS, not just an specific one. Something like a system message (WM_*), which is sent to ALL the applications (including mine) to notify them of a process start.
DMASTER
|
|
|
|
|
Hello Developer611,
Sounds like you need SetWindowsHookEx() with WH_CBT. Look it up in MSDN. It may help you.
- Bio.
|
|
|
|
|
|
Could someone please help me to find out why the following code asserts:
CDialog dlg = new CDialog();
// hide edit control in dialog
CEdit *pEdit = (CEdit*)dlg.GetDlgItem(IDC_EDIT1);
pEdit->dlg.ShowWindow(SW_HIDE);
This line should read derefferenced pointer to pEdit but I cannot write it correctly here!! pEdit "points to" dlg.ShowWindow(SW_HIDE);
pEdit->dlg.ShowWindow(SW_HIDE);
dlg.DoModal();
This asserts in
CWnd* CWnd::GetDlgItem(int nID) const
{
ASSERT(::IsWindow(m_hWnd));
Thanks for reading
Vaclav
|
|
|
|
|
I think your error is in this line pEdit->dlg.ShowWindow(SW_HIDE); did you use of debugger?
|
|
|
|
|
Vaclav_Sal wrote: CDialog dlg = new CDialog();
...
dlg.DoModal();
How are these compiling?
Vaclav_Sal wrote: CEdit *pEdit = (CEdit*)dlg.GetDlgItem(IDC_EDIT1);
Until the base OnInitDialog() has been called, you can't use a non-existant window.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Ok,
I am totally confused here. I am obviously missing some basic.
It compiles just fine and partially works - wihtout doing OnInitDialog();
The actual dialog is used in CListView as a "pop up" dialog.
I can access and change the dialog CEdit "control" variable if it is assigned as a text.
I changed it to control and tryed SetDlgItemText(IDC_EDIT1,strText);
and it did not change the text of the control. I cannot figure out how to trace this SetDlgItemText because it does not return anything.
I checked CodePoject and found good tutorial on CDialog but it stated that the "controls" must be created again at run time to change some of the states.That does not make sense to me.
Thanks for your help.I'll keep working on it.
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: I am obviously missing some basic
Yes
MFC windows are created in a two-step process:
1) The CWnd (or derived) object is created
2) the Windows OS object (HWND) is created
MFC windows are destroyed in a similar two-step process:
1) the Windows OS object (HWND) is destroyed
2) The CWnd (or derived) object is destroyed
Any operations on a CWnd object between these 2 steps, which require an
HWND to execute, are going to fail, since the HWND is NULL.
In your code, you call dlg.GetDlgItem() before dlg's HWND is created -
that will fail.
Make sense?
In this case, if you want a control created initially invisible, then
you could just turn off the visible flag in the dialog resource for that
control.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark.
It is begining to make sense.
But I still don't get the corellation between the dialog resource and the code.
It almost looks like I have to duplicate the controls in code.
I got the following woking - somewhat.
Sorry but it has some garbage in it.
I still have some concerns -
The C_Dialog_Block dlg; assigment "runs" the constructor and initializes the controls. What I do not see is how does the OnInitDialog gets involved.
The CreateEx will do - but I cannot figure out how to create the control in the dialog window - it obviously ends up in the parent view ( either this or m_hWnd works).
I have "Indside Visual C++" and using their examples and it still does not compute!
Their example does all the control initialization in OnInitialDialog and as I said I cannot figure it out how it is called.
PS I forgot to mention that the whole mess is in splitter view - I am trying to edit CListView using modal dialog.
Anyway,
as always thanks for your help, I think I will work on it for a while and hopefully get it.
Cheers Vaclav
C_Dialog_Block dlg; // = new C_Dialog_Block();
int iIndex = 0;
int iVisible = 0; // count visible items
The m_item1 is a CString - not a CEdit and this works just fine
strText = m_columnHeader[iIndex++].strText;
dlg.m_item1 = strText;
The m_item3 is CEdit control
dlg.m_item3.CreateEx(WS_EX_CLIENTEDGE, // Make a client edge label.
_T("STATIC"), strText,
WS_CHILD | WS_TABSTOP | WS_VISIBLE ,
10, 10, 100, 100, m_hWnd, (HMENU)IDC_EDIT3);
This will show up in parent view at correct coordinates - need to go to dialog.
The control ID - (HMENU)IDC_EDIT3 seems to have no effect.
dlg.DoModal();
return 1;
|
|
|
|
|
CInternetSession session;
thrown an assertion error in afxwin1.inl Line 27.
what must i do?
|
|
|
|