|
It is said that "Once a reference is initialized to an object, it cannot be
changed to refer to another object."
But does this only apply locally. The following codes can compile successfully inside function which is controdict with the rule
int x;
int y;
int& r = x;
r = y;
-----------
Another question
extern class A;
void h(A*& a)
{
...
}
int main() {
A a;
h(&a);
A *b = New A;
h(b)
Why line 2 can't pass the compilation? I see no difference between "&a" and "b"
|
|
|
|
|
There's no contradiction.
Check this modified code
int x = 10;<br />
int y = 20;<br />
int& r = x;
r = y;
r += 10;
cout << r << " " << x << " " << y ;
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;<br />
A* p1;<br />
A* &r1 = p1;
p1 = &a1;
r1 = &a2;
<br />
A* &r2 = &a2;
|
|
|
|
|
I see your point.
int x = 3;
int y = 1;
int& r = x;
r = y;
int main() {}
The above codes can't pass the compilation and with a error message "'r' : missing storage-class or type specifiers", It doesn't make sense to me, here the last line just assign "y" to the object "r" refers which is "x", and when I move it to local function the error disappears, why?
|
|
|
|
|
YongSheng Li wrote:
int x = 3;
int y = 1;
int& r = x;
r = y;
int main() {}
The first three lines are variable declarations that include their initialization. That's valid at the file scope.
The fourth line (r = y; ) is an assignment, which is not legal at the file scope; it's only valid in the body of a function.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
|
|
S. Senthil Kumar wrote:
Beat me to it by a minute
What that supposed to means?
|
|
|
|
|
You can only declare and initialize variables outside of functions, you can't write statements like r=y .
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello to all members
In a project which is in mfc some data is shown on a
window is there anyway to show some background image
Ankit Aneja
|
|
|
|
|
Ankit Aneja wrote:
window is there anyway to show some background image
Handle WM_PAINT and then draw image on the BackGround of Window!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
i am showing my data in Listcontrol and want to show image on background
of that listctrl behind my data
i found CListCtrl::GetBkImage
and example
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
LVBKIMAGE bki;
// If no background image is set for the list view control use
// the Microsoft homepage image as the background image.
if (pmyListCtrl->GetBkImage(&bki) && (bki.ulFlags == LVBKIF_SOURCE_NONE))
{
pmyListCtrl->SetBkImage(
TEXT("http://www.microsoft.com/library/images/gifs/homepage/microsoft.gif"),
TRUE);
}
but not undestanding how to use this
also tried like this
void CXListCtrl:: SetBkImage( LVBKIMAGE* plvbkImage )
{
SetBkImage(
TEXT("http://www.microsoft.com/library/images/gifs/homepage/microsoft.gif"),
TRUE);
}
Ankit Aneja
|
|
|
|
|
Hi,
it seems that you try to set a gif background image.
I think the only thing that can be shown is a HBITMAP or a CBitmap.
To load a bmp file, you can use following code:
CBitmap* LoadBitmap(const CString& Path)
{
CBitmap* attempt = new CBitmap;
HBITMAP hbmp = (HBITMAP)LoadImage(0, Path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (hbmp && attempt->Attach(hbmp))
{
return attempt;
}
delete attempt;
return 0;
}
Regards
|
|
|
|
|
Thanks
in OnInitDialog() where i am inserting coloumns
i write the following code
// Insert Background Image into the ListControl
LVBKIMAGE bki;
if (m_ctrlListNews.GetBkImage(&bki) && (bki.ulFlags ==LVBKIF_SOURCE_NONE))
{
m_ctrlListNews.SetBkImage(TEXT("C:\\close.bmp"),TRUE);
// Use your own Image Address Here
}
and it works but image is not transparent
means it cuts for lines and columns where some data is
filled
is there any way to make the image transparent so that it can be seen behind
the text shown in list control
Ankit Aneja
|
|
|
|
|
Ankit Aneja wrote:
is there any way to make the image transparent so that it can be seen behind
the text shown in list control
Try this:
m_ctrlListNews.SetTextBkColor(CLR_NONE);
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
m_ctrlListNews.SetTextBkColor(CLR_NONE);
i had tried this thing but nothing happens
Ankit Aneja
|
|
|
|
|
Sorry,
I've never dealt with transparency in MFC so far. There should be some articles around here, but I guess transparency is a fiddly thing...
Regards
|
|
|
|
|
Hello All
I have called SetThreadLocale() to notify windows that my ANSI-mode program must be treated as an arabic program, and characters and strings should use codepage 1256.
but this does not work. texts are not shown correctly. what should I do?
|
|
|
|
|
I have wrote a application that use large part of memory and cpu
How can i set my application priority very high
and reserved enough memory and cpu usage for it
Can you help me?
|
|
|
|
|
|
You can raise the probability of the application getting higher CPU cycles, but you can't raise virtual memory beyond a certain limit. You can use a maximum of 2GB out of the 4 GB address space (3GB if you use the /3GB switch).
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Can you writing program a clock by ActiveX control using ATL?
|
|
|
|
|
Hello,
I am attempting to write an app to do the following things:
1) Render DirectX in multiple views of the same document, where the views are created in a static splitter window.
2) Be able to easily synchronize updates between view windows (both windows display time series, want to be able to scroll through time series).
3) Be able to easily control the DirectX stuff (e.g. handle swap chains, window handles, etc.).
I've written most of this already, but not well, and am starting over from scratch (DirectX and synchronizing are handled by going back and forth between MainFrame and view objects).
I was originally trying to create the two views as based on one class (that would handle window specific rendering, other stuff), and make those views members of another class (to handle the DirectX code necessary to render two windows using a single device interface, and to easily synchronize data between the views). However, it seems to me (and I may be wrong) that the dynamic view creation is not capable of this, i.e. I could not create views in a splitter window that were members of another class (but I may be wrong about this, too).
Any suggestions on a clean and robust way to implement something like this? One thought I had was to put the code for dealing with both windows in the CDocument class (since it and the views have inherent access and messaging), but this seems like a kludge.
Any help would be appreciated - please ask me to clarify if the above doesn't seem clear.
|
|
|
|
|
After chasing around the process of calling CMyDialog::OnCreate(), I stopped at CWnd::OnWndMsg
BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
...
union MessageMapFunctions mmf;
mmf.pfn = lpEntry->pfn;
...
case AfxSig_is:
lResult = (this->*mmf.pfn_is)((LPTSTR)lParam);
break;
}
Where mmf.pfn is a pointer to CCmdTarget member function. So here MFC assigning
to one field(mmf.pfn) of a union(MessageMapFunctions) with CMyDialog::OnCreate(...) and reading from another(mmf.pfn_is).
What is under the hood, cast between two totally different function signature, is it safe thing to do? Can anybody provides any detail?
|
|
|
|
|
Are you having a problem with calling CMyDialog::OnCreate()? If so, it's unlikely to be related to a bug in in CWnd::OnWndMsg...
Or are you just trying to understand how it works?
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi Jose:
I have no problem calling OnCreate(), I just trying to understand the question that in my previous post!
|
|
|
|