There's no contradiction. Check this modified code int x = 10; int y = 20; int& r = x; // make r refer to x r = y; // this does not change the reference, value of y is copied to r, i.e., to x r += 10; // this will modify x, not y, because r still refers to x, not y cout << r << " " << x << " " << y ; // prints 30 30 20
For the second one, you have created reference to a pointer in the function parameter A*& a
. By this it means a
refers to a pointer of type A
which it can modify. However when you pass &a
to the function h
, &a
is not modifiable. Check this sample code A a1, a2; A* p1; A* &r1 = p1; // Ok, r1 refers to a modifiable pointer p1 p1 = &a1; // p1 points to a1 r1 = &a2; // now p1 points to a2 A* &r2 = &a2; // ERROR: &a2 is not modifiable, &a2 is a constant pointer
Bhaskar
Posts
-
Reference question -
a Dialog Bar Question !Since the dialogbar object is a member of frame class. You need to get the dialog bar object through AfxGetMainWnd. Check this
void CTestView::OnBnClickedButton1() { CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd(); if (pFrame) { pFrame->m_wndDialogBar.SetDlgItemText(IDC_MYSTATIC, "Hello"); } }
This is a message handler of a form view class The m_wndDialogBar is a public member of CMainFrame class IDC_MYSTATIC is the id of the static control in the dialog bar. You must change the id of a static control from IDC_STATIC to another. -
total number digit in string name.Try this. It works.
CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%0*d",numDigit-prefix.GetLength(),startNum); k = prefix + k; cout << (LPCTSTR) k;
-
scanf up to tab?You can limit the no of characters to extract with scanf. char s[BUFFERSIZE+1]; scanf(" %*[^\t]", BUFFERSIZE, s);
-
Knowing mouse state?Use GetCursorPos
-
scanf up to tab?Use scanset.
char s[80]; scanf(" %[^\t]", s);
-
set bitmap into buttonIf you are using MFC, use the MFC class CBitmapButton class
-
Message Handler for dynamic CbuttonUse this macro to map a contiguous range of control IDs to a single message handler function for a specified Windows notification message, such as BN_CLICKED. ON_CONTROL_RANGE(wNotifyCode, id1, id2, memberFxn ) From the MSDN library
-
dialog box for entering the system path....I think you want a select folder dialog box. This can be done using the SHBrowseForFolder api function. See http://www.codeproject.com/shell/cxsbrowsefolder.asp for a class that encapsulates this function
-
question on use of global scope operatoryou cannot use :: operator for constants defined using #define. It can be used only for declared identifiers. Look the following code
#define CONSTANT1 100 const int CONSTANT2 = 100; main() { cout << ::CONSTANT1; // this is an error cout << " " << ::CONSTANT2; // this is OK }
-
Adding to IE context menuhi, I wanted to know if there was a way to add to IE's context menu, but not through the registry. My menu items change at the time of invoking the context menu and the menu needs to be dynamic. I have got as far as displaying my menu prior to IE context menu. If the user cancel my menu IE's context menu is displayed. But I need to put my menu to IE. Thanks