Well what I meant was void FOO(int* p){*p+=1;} int* i = NULL; FOO(i)
If you use references then this sort of problem just can not occur. So it is not that an error will be caught at compile time, there can be no error if you use references. Anyway replacing pointers with references is not always feasible, if the concept of null object is valid, or if the pointer must be rebound (references cannot.) I agree and that is what I said.
souldog
Posts
-
what is difference betwn pointer and referece -
what is difference betwn pointer and refereceI would say it is not a matter of style and convenience. In most circumstances only pass pointers into functions if you need the possibility that the object is not valid, i.e. null pointer. It is a matter of the compiler catching errors or having them show up at runtime.
-
what is difference betwn pointer and refereceReally? try compilling these const int* p = NULL; and int& l = NULL;
-
Switching Between View in MDIWell have a look at CMDIFrameWnd::MDIActivate
-
How do you use MM_ISOTROPIC mode with a CScrollView?You are not supposed to use MM_ISOTROPIC with scroll views. The Scroll view has a function SetScaleToFitSize which will scale the view to the window size.
-
height of the header of windowYou are not giving enough information. I will assume that you have a window and you want to fill its client area with another window. Use GetClientRect() to get the client area. You are probably using GetWindowRect()
-
docking a modeless dialogWhat you want is called a dialog bar. Take a look at CDialogBar or look at this http://codeguru.earthweb.com/docking/devstudio_like_controlbar_2.shtml[^]
-
vector and deleteNo, No, No.. Don't do this. Do not store the pointer returned by new anywhere else except the vector. All access to that object should be through the pointer stored in the vector. Your problem here is that you have many copies of the pointers floating around. You need to redesign your application so that this is not the case. if the code is inside the class pointed to then it should not be possible to call it in any other way except through the pointer stored in the vector, so you don't need to check it for NULL This is how it should be done. ANy other way and you have Code that is very hard to maintain and very error prone. Can you explain why and how you are possibly calling a function in a class the instantiation of has just been deleted from memory.
-
Class Problem?Not this way. You have created the object on the stack in the first function and so the object is destroyed when the function returns. Therefore, your pointer to this object is no longer valid outside the scope of the first function. There are lots of ways to approach this problem, but one is to return an object of type A by value from the first function and assign it to another object of type A which is declared outside the function. The best method depends on the cost of creating and assigning the object.
-
map erase issueBy the way, if you want to make the map empty then just call clear()
-
DialogI will answer 1. Handle OnNcHitTest and tell the system the mouse click was on the client area when it is actual hit on the caption. Here is the code
UINT CMyDlg::OnNcHitTest(CPoint point) { UINT ret = CDialog::OnNcHitTest(point); if(ret == HTCAPTION ) return HTCLIENT; else return ret; }